Hi,
I am a total newbie in programming and try to code my very first game.
However I have problems with simulating the turning radius of a car, is there any solution to that?
In my game I am currently rotating my vehicle like shown below, but in real life a car should have always a steady turning radius, no matter of speed. Am I right? In the code below the car turns nearly on the spot when driving with 0.000000001 of speed...
how can I prevent that?
void loop() {
if( currentSpeed != 0 ) {
if( desiredRotation > 0 ) {
rotation += rotationSpeed;
desiredRoation -= rotationSpeed;
dx = Math.sin( rotation );
dy = Math.cos( rotation );
} else if( desiredRotation < 0 ) {
rotation -= rotationSpeed;
desiredRoation += rotationSpeed;
dx = Math.sin( rotation );
dy = Math.cos( rotation );
}
x += dx * speed;
y += dy * speed;
}
}
There are a lot of games out there which make extensive use of cars, tanks and other vehicles - like Halo, Battlefield, GTA, etc.... . So there has to be some kind of common practice in simulating car behaviours!?
Any sources/articles to this topic are very welcome.
Also if you could make comments about my code would be great. I don't know if this is good code or if I can make this code any better, any comments and critics are welcome. I am teaching this stuff myself, so I do not have a chance to get my code reviewed otherwise.
Thank you very much
With Best Regards