2d car physics / simplest way for position change in curve

Started by
2 comments, last by sebflash 17 years, 7 months ago
Hi, I'm searching for the simplest way to simulate the position change in a curve in a 2d car racing game. The car has position at x,y and movement change/speed (=velocity) is at vx,vy. So, if car is driving down vy is positive and vx is zero. If car is driving to right vx is positive, vy is zero. But, do you now a smart and simple way how to change vx, vy if the car is steering to left/right in a curve? I have found a lot of tutorials on net, but most of them are just too complicated for what I need. BR, Sebastian
Advertisement
If the car's orientation is represented as a single angle, you can then compute the velocity as:
vx = cos(angle) * speed;vy = sin(angle) * speed;
You could then steer the car with two direction keys, one which decreased the angle and one which increased it.

That's about the simplest control scheme possible. Is that what you're looking for?
E.g. you may simulate an acceleration perpendicular to the current velocity. For that purpose first get the perpendicular, e.g. as
vp := perp(v) = ( vy , -vx )

Then scale it by a factor f that designated how much the steering wheel is rotated. Use 0 for straigt forward and e.g. 5% and 10% for wide and sharp curves to the right resp. -5% and -10% for such curves to the left:
vp * f

Add this to the current velocity to yield in the new one
v' := v + vp * f = ( vx + f * vy , vy - f * vx )

EDIT: And at last, scale the resulting velocity so that its magnitude becomes the required value, e.g.
v' * | v | / | v' |

EDIT 2: Okay it's simple, but not as simple as jyk's solution.

[Edited by - haegarr on September 9, 2006 5:32:56 AM]
Quote:Original post by jyk
If the car's orientation is represented as a single angle, you can then compute the velocity as:
vx = cos(angle) * speed;vy = sin(angle) * speed;
You could then steer the car with two direction keys, one which decreased the angle and one which increased it.

That's about the simplest control scheme possible. Is that what you're looking for?


Thanks. Just tested, works good enough for what i need!

This topic is closed to new replies.

Advertisement