Search code examples
algorithmcar-analogy

Car steering algorithm?


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!


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.