Make a custom movement component that extends character movement component and add a custom function to override gravity
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/CharacterMovementComponent.h"
#include "CharacterMovementComponentEX.generated.h"
/**
*
*/
UCLASS()
class MYGAMENAME_API UCharacterMovementComponentEX : public UCharacterMovementComponent
{
GENERATED_BODY()
UFUNCTION(BlueprintCallable)
void SetGravDirection(const FVector& GravityDir);
};
// Fill out your copyright notice in the Description page of Project Settings.
#include "CharacterMovementComponentEX.h"
void UCharacterMovementComponentEX::SetGravDirection(const FVector& GravityDir) {
Super::SetGravityDirection(GravityDir);
}
then inside of the character swap out the movement component with the new one
.h
// needs constructor (eg. class is called AMyCharacter)
AMyCharacter(const FObjectInitializer& ObjectInitializer);
cpp
/* needed include code */
#include "CharacterMovementComponentEX.h"
AMyCharacter::AMyCharacter(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer.SetDefaultSubobjectClass<UCharacterMovementComponentEX>(CharacterMovementComponentName))
{
// rest of your init code here if needed
}
With SetGravDirection you should be able to pass in a vector. Just to a cast to the CharacterMovementComponentEX class before calling the function.