Click to See Complete Forum and Search --> : C to AS (Car Physics)

09-07-2002, 06:26 AM
Hello all, my first post in the Maths and Physics forum. What im trying to do is convert some car physics scripts i found in C to use in a flash game. But im having some trouble...


The top file seems to work but only in one direction :confused: . The middle file i tried to add some code to make it work in all directions - but failed.

And the bottom file is the original 'c' source code.

Ericlin - BlinkOK sent me here from the games forum

"ericlin simply could not resist something like this"

so i hope your going to help :p hehe.

09-07-2002, 01:09 PM
I took a glance. I can not fix it. Some clues I found:

1. the steerAngle should be an arc of PI format. So when Key.isDown(Key.LEFT and RIGHT), the change of steerAngle should be convert to arc.

2. the main force to drive the car seems to be the variable ftractionx (I am not sure, but it is the force related with throttle). The equation seems based on the coordinate system of car, not global. Maybe this should be adjusted according to the rotation of the car. I suspect the calculation equation for resistancy and lateral force etc may also based on the coordinate system of the car. In the first line you define sn and cs, but I did not see them used anywhere.

I am not very sure about all of these. There are so many variables that need to clarify. It is difficult to debug.

09-07-2002, 06:37 PM
Hey, thanks for replying. Have a look at the 'Car Physics 3' file... I realised the same thing as you about the cars variables being local and not global and see need to be changed as the car rotates. I attempted to add something to do this (hence the 'sn' and 'cn' defined at the top). You can look at the original C source under the 'physics' section to find out how i tried to do it. Unfortuantly it appears to drive even less like a car! :angry:

- T

09-07-2002, 09:38 PM
The author use position_wcx and position_wcy to represent the position of the car on the stage; I dont know quitely the equation about sn,cs is. I feel a little strange. Anyway, I adopt his equation. The positionx=200 and position>400 are replaced by position_wcx. Never-mind, you can change in the equation position_wcx to positionx directly.

However, the car goes in the wrong direction. When we just power up without steering, the car goes to the right side rather than forward. So I swap the _x,_y; It is better now.

Since angle is used in sin and cos, the unit must be rad. So _rotation=angle should be adjusted.

Every thing seems better now, but the car keep rotating. I make the torque less, (divide it by 100), and the car looks better.

So, the car may need to increase the value of "inertia", or maybe some physics is not right in the c source codes.

Here is the fla: