Public Group

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

This topic is 4478 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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

##### Share on other sites
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?

##### Share on other sites
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]

##### Share on other sites
Quote:
 Original post by jykIf 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!

1. 1
2. 2
3. 3
Rutin
13
4. 4
5. 5

• 26
• 11
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633698
• Total Posts
3013412
×