How to get current acceleration/deceleration of actor in BP?

I’m trying to tilt an actor based on the current acceleration.

Using the Character Movement component with Get Current Acceleration, i am able to get the pure acceleration of the actor, meaning just the acceleration based on input. If i let go of the controls, my character decelerates, but Get Current Acceleration returns (0, 0, 0). This, sadly, is intended behaviour according to the documentation.

I want to get the true acceleration in a physical sense. meaning a backwards facing (negative) acceleration vector, every time my character slows down.

Do you have any idea on how i can achieve this?

I want my character to tilt backwards, when he decelerates, similar to the behaviour described in this video by David Rosen of Wolfire Games

Answering my own question with a workaround:

I might go the route of storing the current velocity every tick and then calculate the “true” acceleration using the current velocity, the velocity stored in the previous tick and Delta Seconds.

However i’m not satisfied with this solution, as im sure that the engine already calculated this internally and i don’t trust my mathematical ability to create a stable system. Reinventing the wheel and all that.


UPDATE: My current setup looks like this:

outputs -980.0 while jumping. This setup seems to work for the moment.

UPDATE2: Sadly this solution does not solve having the character tilt towards acceleration. As soon as the character reaches teminal velocity ( Max Walk Speed ) the effective acceleration is 0 and the character stands upright again. Oh well…

The problem here is that your acceleration is coming from the input component. Your deceleration on the other hand is coming from LACK of input. So you’d have to go into the systems that convert lack of input into slowing down, and figure out how to expose that. I don’t see anything in the engine that exposes that for you. I think your velocity calculations are the best way to handle this in blueprint currently.

as i understand it, the Character Movement component handles deceleration as it handles the values for Max Deceleration, Breaking force etc. But the current deceleration does not appear to be exposed.

That component does expose this: Get Last Update Location | Unreal Engine Documentation
At least then you would not have to store it locally.

hey, thats useful

edit: Whoops not really. It exposes location and I need velocity. I rather store “last tick velocity” locally, because if I use location to calculate acceleration, I have to worry about cases of teleportation and the likes.

How about this one: Get Last Update Velocity | Unreal Engine Documentation
:slight_smile:

i didn’t look and you are awesome!

EDIT: I should test before i comment. Get Last Update Velocity returns exactly the same value as Get Velocity. The doc sais:

Returns the velocity at the end of the last tick.

so, this seems to be a problem. I would need to wait for the current velocity to update, but thats beyond the scope of my implementation.

You could give a margin say 20.0 when near to max velocity and set it as accelerating if the actual speed is within this margin