Archived

This topic is now archived and is closed to further replies.

foonk

simple acceleration

Recommended Posts

hey i''m trying to accelerate a car or any object, right now i''m just increasing how much it moves along the z axis when you hold down the up arrow, and this is not realistic at all, i am guess i got to base it on time, so a faster computering wont accelerate it faster but i have know idea where to begin on this, do i limit when it redraws the frame, that sounds bad and i wont do that, or increase the speed in relation to the time that passed oe something, i really am not sure, can you guys give me any tips? or links to some good pages, thanks m

Share this post


Link to post
Share on other sites
Store the velocity in distance/time format. So, if you want it to move 5 ''units'' every second we could say: 5u/1000ms => 0.005u/ms. Now, we keep track of the time since we last moved it. If it has taken 30ms since then we multiply the velocity by that to find the distance moved: 30ms * 0.005u/ms => 0.15u. So, we increment the distance in the whatever direction by 0.15. Repeat this for each update now.

Share this post


Link to post
Share on other sites
thanks for that null and void,
if i understood you right, i have in the key pressed code, it checks when it was last increased and if its been however long i increase the speed its moving, but this still doesn''t seem realistic to me, it gets to it max speed to quick, or is what i''m looking for more advanced?

Share this post


Link to post
Share on other sites
velocity += acceleration * changeintime
position += velocity * changeintime

So then, when a key is down just set to acceleration to whatever you want acceleration to be (it would be a constant, though real acceleration is usually a curve not a flat line if you know what I mean). And when the key is not down (keyup(); ) you set acceleration back to 0 meaning its not accelerating.

BTW changeintime is the amount of time that has passed since the function was last called.

Hope that helps somewhat.

||--------------------------||
Black Hole Productions
http://bhp.e-chrono.net/
Resident expert on stuff
max621@barrysworld.com
||--------------------------||

Share this post


Link to post
Share on other sites