How do I create movement with acceleration?

I want to let the player (a B E A N) first move slowly (accelerate it like a car) and then let it move at a constant speed and in the end let it break like reverse acceleration.

How is this possible?

Thanks in advance

Hi @SayHiToMePls! You can start your move speed with for example 0.1 and then multiply the move speed by dt in the update function until the maximum speed is reached. To slow down you can do the opposite. You will have to adjust the values ​​until the desired result is achieved.

1 Like

I think I found the solution by now: I should use applyImpulse for my bean since I made it a rigid body.

Do you maybe know how I can get the current speed into a variable to make a simple check?

Depending on your needs and what you want to check. You can get the entity velocity by reading a property of the rigidbody:

entity.rigidbody.linearVelocity;                // vector, useful for checking velocity on a specific axis
entity.rigidbody.linearVelocity.length();       // number
entity.rigidbody.linearVelocity.lengthSq();     // number (cheaper for CPU)
2 Likes

So you mean I should do something like this:

var velocity = entity.rigidbody.linearVelocity.lengthSq();

If not, how would you do that?

Yes, that looks fine.

1 Like