Determine if player is accelerating

To determine acceleration you will need to remember the velocity of your character from the previous frame (the last time you got a tick). I think that’s what the movement component is doing for you. In your own class you can achieve the same thing.

Here’s some quick code for you. I turned bIsAccelerating into a function.

So, add a property to your class declaration (in your .h)



UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class YOUR_API UYourComponentNameHere: public UActorComponent
{
    GENERATED_BODY()

    // .... some code

protected:
    UPROPERTY()
    FVector _previousVelocity = FVector::ZeroVector;

    UPROPERTY(BlueprintReadOnly)
    FVector _currentAcceleration = FVector::ZeroVector;

public:
    UFUNCTION(BlueprintCallable)
    bool isAccelerating()
    {
        return _currentAcceleration.Size() > 0.0f;
    }

    UFUNCTION(BlueprintCallable)
    FVector currentAcceleration()
    {
        return _currentAcceleration;
    }
};


Then in your TickComponent (in your .cpp):



// Called every frame
void UYourComponentNameHere::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
    Super::TickComponent(DeltaTime, TickType, ThisTickFunction);

    // calculate the current acceleration
    FVector deltaV = GetOwner()->GetVelocity() - _previousVelocity;
    _currentAcceleration = deltaV / DeltaTime;

    _previousVelocity = GetOwner()->GetVelocity();

   // make sure you call your code after the above
}