A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: C to AS (Car Physics)

  1. #1
    Senior Member random10122's Avatar
    Join Date
    Mar 2002
    Location
    Sheffield, UK
    Posts
    1,747
    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...

    http://www.moor47.fsnet.co.uk/fla/car_physics_2.fla
    http://www.moor47.fsnet.co.uk/fla/car_physics_2.swf
    http://www.moor47.fsnet.co.uk/fla/car_physics_3.fla
    http://www.moor47.fsnet.co.uk/fla/car_physics_3.swf
    http://www.moor47.fsnet.co.uk/fla/car_physics.c


    The top file seems to work but only in one direction . 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 hehe.

  2. #2
    Senior Member
    Join Date
    May 2001
    Posts
    1,838
    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.

  3. #3
    Senior Member random10122's Avatar
    Join Date
    Mar 2002
    Location
    Sheffield, UK
    Posts
    1,747
    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

  4. #4
    Senior Member
    Join Date
    May 2001
    Posts
    1,838
    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:
    http://ericlin2.tripod.com/forum/car_physics_e.swf
    http://ericlin2.tripod.com/forum/car_physic.zip

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center