Accurately Simulating Car Movement in Flex

Posted on December 30, 2009 by Tony Fendall.
Categories: Adobe, Flex.

When I find time (which is increasingly less often), I always like to set myself technical challenges to solve.  I enjoy the challenge of it, and every so often I actually produce something which someone else could find useful.

Car Movement In the last couple of days I have been trying to accurately simulate the movement of car (two steering wheels, and two fixed wheels).  This is more complicated than it first appears because, when the car is turning, it is actually rotating around a point which is outside itself.  The diagram to the right should help to show what I mean.

Getting this form of motion to work properly involves some complicated co-ordinate geometry to make points rotate around other points across multiple frames of reference.  It took me a while, but I finally managed to get it working today.  You can check out the result below :)

CLICK HERE TO VIEW SOURCE

Comment on December 30th, 2009.

Wow, it works pretty well. Now you just need to make the speed and steering react to arrow-key presses. :D

Comment on December 31st, 2009.

I considered hooking up the arrow keys, but that didn’t give the feel that I was going for. I wanted people to realize how analogue the movement of a real car is.

Comment on January 27th, 2010.

Hi Tony
Awesome demos , I am working in flex for past 1 year and wanted to get my hands on game development , i am a newbie in game development , i seen your world builder code ,it was super cool , can i get ur Let’s Go Walk About- Flash Games in Flex code to study or some tips , how do i start game development in flex , i know the RIA part of flex though

Thanks for posting good demos , looking forward to see some more :)