Car Movement: Acceleration, Braking, Turning & Reverse
This is a GTA style top-down view car driving game example. This fla shows you how to implement car movement; Acceleration, Braking, Turning & Reverse.
Custom Car Settings:
- speedMax - max car speed
- speedMaxReverse - max car speed in reverse
- speedAcceleration - acceleration speed
- speedDeceleration - braking speed
- groundFriction - how far the car rolls before stopping
- steeringMax - max rate at which car can turn
- steeringAcceleration - how fast the car starts turning
- steeringFriction - how fast the car corrects itself (when you “let go of the wheel”)
Preview
7 Comments to Car Movement: Acceleration, Braking, Turning & Reverse
how come i can’t see the actionscript code, the flash file loads, i wanna try play around with the script, but i cant see it, i have Adobe Flash CS3
KriptoKnight, take a look on the timeline.
September 12, 2009
Cool, thanks pradvan just found it.
Cheers mate, it really helps with my school ITS assingment(we have make a actionscript 2 game and make a totourial on how to make for the younger grades)
May 20, 2010
love the dynamics of this code but for the life of me can’t find why the car seems to drift to the top/left when no arrows are pressed. happens when driving around and then stopping or just letting the car stop by not touching the keys. i tested it out in the embed above and it does the same thing too. so.. just curious if you might know what might be the issue. thanks
livingpaint, I had not noticed it before, but it’s definitely difting. I’ll have to take a look and fix it.
Thanks for bringing it up!
Phil
May 25, 2010
Pradvan, one thing I noticed, while testing it out and trying to come up with a solution myself, is that if you drive it around and are able to point the car facing down (straight - 6 o’clock) the drifting doesn’t occur. Almost any other degree from that rotation will cause the car to drift. Which might be the code relating to the car correcting itself when the keys are up. Hope this help with the debug.
livingpaint,
I finally got around to checking out the script. Adding a minimal speed check fixes the drifting. Just add this code right below the part that says “// friction” in the runGame function:
//
if(speed < 0.01)
{
speed = 0
}
//
Once again, thank you for pointing it out.
Phil
Leave a comment
You must be logged in to post a comment.
CategoriesLinks |

September 10, 2009