Physics engine: how do you simulate top speed?
Posted: Sat Mar 18, 2023 4:52 am
I have a physics body that I move around using impulses on the x and y axis. Positive X impulse moves the body to the right and negative X impulse moves the body to the left. With mass applied, I can get a nice seamless acceleration effect thanks to the hard work the Box2D does for me.
If I make up some numbers for example, if my body applies +1000 x impulse per second it will move to the right side of the screen in an ever increasing speed. I need it to reach a fabricated top speed and thought I'd ask if there is a 'best' way to do this in harmony with the engine?
The obvious one to me, for each dt, apply the (+1000 * dt) impulse then immediately do a body:getVelocity(). If the velocity is over the top speed then reduce that top speed with body:setVelocity(). I suspect that is a poor approach due to the setVelocity overriding the engine's natural way of applying physics.
What method have you used in the past that works well with the engine?
If I make up some numbers for example, if my body applies +1000 x impulse per second it will move to the right side of the screen in an ever increasing speed. I need it to reach a fabricated top speed and thought I'd ask if there is a 'best' way to do this in harmony with the engine?
The obvious one to me, for each dt, apply the (+1000 * dt) impulse then immediately do a body:getVelocity(). If the velocity is over the top speed then reduce that top speed with body:setVelocity(). I suspect that is a poor approach due to the setVelocity overriding the engine's natural way of applying physics.
What method have you used in the past that works well with the engine?