This makes it so when the player stops apply input, 'IsAccelerating" returns false immediately
However, when I try and “GetCurrentAcceleration” this does not exist in C++, I tried to look at the code for the “GetCurrentAcceleration” node, however all it does is return acceleration, and shows no function how it is calculated.
This is my current code, and it returns false only when the character has completely stopped.
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)
// 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
}
Thanks for the reply! Trying to understand why I cannot call the function though. After looking into the example Third Person C++ code, it almost seems as if I am getting the wrong component? In the example, the code for getting character movement is GetCharacterMovement(); however this is called from the Character class, not the anim class. Is there a way to call GetCharacterMovement from my anim class targeting the character?
Timtimmy, the class that I am trying to call this from inherits from AnimationInstance. I am trying to turn my AnimBP Event Graph into C++ code. In BPs, i have these values determined from the characters class, then casted to the character class from the animbp. I was trying to get these values from the character class within the animinstance class