simple acceleration
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
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.


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?
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?
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
||--------------------------||
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
||--------------------------||
||--------------------------||Black Hole Productionshttp://bhp.nydus.netResident expert on stuffmax621@barrysworld.com||--------------------------||
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement