This project has moved and is read-only. For the latest updates, please go here.

Controlling a 2d car

Topics: Developer Forum
Mar 24, 2007 at 2:42 PM

I am new to XNA and the Farseer Engine. I am wanting to create a simple 2D top-down view racing game to learn game programming in general. Firstly I am trying to get a simple sprite car (in top-down view) to be controlled via the keyboard. From looking at the demos in the Farseer Engine I am using the .ApplyForce() and .ApplyTorque() methods of the RigidBody class to move the car (similar to the example in the demo4 project), which moves the sprite but in an unrealistic manner. Is it possible to simulate car movements in the engine (in top down view) using these methods or are there other methods that would work?

Does Gravity in the Engine work in top-down view?

Thanks alot
Mar 24, 2007 at 7:21 PM
Edited Mar 24, 2007 at 7:22 PM
For a top down view of car movement, gravity probably won't come into play. You will need to apply forces at the wheel locations of your vehicle. The trick will be figuring out what forces to apply. I think if you google you can find some info on it. Farseer doesn't have any built-in car physics helper math, but it will let you apply forces at a specific location (at the wheels for instance.)
Applying forces at the wheel locations will automatically apply the torque to the car.
Mar 28, 2007 at 3:04 PM

I have been playing around with the .ApplyForceAtLocalPoint() method on the car's RigidBody object. When the left keyboard key is pressed I apply a random force (for now) to the left front wheel. When the right keyboard key is pressed I apply a random force to the right front wheel. When the car moves the local points on the front wheels where forces are to be applied next time changes. I am having difficulty recalculating the local points again. Can you please advise?