Hi,
Can someone tell me how to calculate/figure out when the car is off the track (so that i can slow it down)?
Can you refer to some tutorials?
Thanks and regards
Check the position of the sprite with the track area. Suppose you have a track that starts at 100 units and ends at 600 units (units are anything, they may be pixels or any other unit you chose).
if (position.x < 100 || position.x + sprite.width > 600)
// Out of track, apply some deceleration
else
// Inside the track, apply acceleration
And this should do what you want to do.
This is completely dependent on how you structured your game. There is no tutorial that will show you exactly how to do what you’re asking simply because every game is different. HOWEVER, you can learn about the math involved and implement a solution yourself.
A track would be tricky because it involves bends, but take a look at this page showing you what you are dealing with:
Then you can move on to something like this:
And an implementation in ActionScript I found: