Question

i've already asked something similar, but now i've the problem to manage and realize a "realistic" steering for a simple 2d (top-down) car racing game.

How can i do a "realistic" steering for the car ? (i use c# but another language is welcome;)) Using Sin and Cos ? If yes, how ? Thanks in advance!

Was it helpful?

Solution

I'm on my lunch break so I can't do tremendous justice to the "best" answer, but the pseudocode looks something like this:

y_change = sin(rotation) * speed;
x_change = cos(rotation) * speed;

car.x += x_change;
car.y += y_change;

you would execute this code in every frame; rotation would be controlled by your steering input, and speed would be controlled by your acceleration input.

OTHER TIPS

You will probably want to use a physics engine that someone else has already created. I've heard good things about the XNA Physics API.

I would imagine that you will have to use sine and cosine, but that is the just the tip of a VERY large iceberg...

Algorithm is:

  1. Record how someone's else drives (using dev. version of game)

  2. (Optional) Split up recording into snippets for variety of usual situations.

  3. Replay recordings in game. (Using suitable snippets and possibly interpolate trajectory between them).

You may also try fuzzy logic and simple steering unit model.

Model would be:

x = integrate horiz_velocity by t
horiz_velocity = intergate steering_angle by t
and steering_angle = fuzzy_steering_function(...)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top