I have a car with speed x, and can accelerate at a rate of 0.5 m/s^2, and can decelerate at a rate of -0.1 m/s^2. Maximum speed is 20 m/s.
To accelerate the car speed, at each frame I need to do:
car.CurrentSpeed = car.CurrentSpeed + 0.5
To decelerate the car speed, at each frame I need to do:
car.CurrentSpeed = car.CurrentSpeed - 0.1
Is this correct?
I have found this answer which suggest the following speed formula:
Speed += ((MoveDirection * MaximumSpeed) - Speed) * AccelerationFactor
- Speed is the current speed the entity is travelling at on the current axis.
- MoveDirection is the direction the entity is trying to travel in on the current axis, 1 is forward, 0 is still and -1 is backwards. All values in between are allowed.
- MaximumSpeed is a constant determining the fastest that the entity can travel on the current axis.
- AccelerationFactor is a constant between 0 and 1 that represents the rate of acceleration and deceleration. 1 is instant, and 0 will never move.
Using the same formula then:
car.CurrentSpeed += ((MoveDirection * 20) - car.CurrentSpeed) * 0.5
What would be the move direction? Can it be the heading?