locked
XNA Vehice Physics RRS feed

  • Question

  • Hi, I've been trying to learn vehicle physics for a car game that I'm making. I took some physics from the SpaceWar starter kit but it doesn't have the right physics for my kind of game. In SpaceWar, when you move the ship and then turn it in another direction, it keeps going in the initial direction. That wouldn't work with a car, which needs to change direction when the wheel does no matter if acceleration is being applied or not.

    Does anyone know of some real easy and good car physics tutorials and examples out there?

    Thanks,
    Dan Castellon
    Monday, January 22, 2007 2:10 AM

Answers

  • RayCar does a nice physics simulation, using the open source ODE graphics engine. It is C++, so you'd have to port both ODE and the sample code to use it with XNA.

    In general, what a car simulation does is:

    0) Update control input.
    1) Collision between chassis and world (typically, a box).
    2) Collision between wheels and world (typically, four rays).
    3) Create joints/constraints for the detected collisions. This includes a tire model with friction, rolling direction, propelling force etc, as well as a dampened spring for the shocks and struts.
    4) Integrate the rigid body of the car chassis using these joints.
    5) Repeat from 0.

    As there is currently no efficient 3D collision detection library for XNA, you'll have to write your own. I wrote one that does spheres, rays, boxes and heightfields, I'm trying to add meshes now. It's a fair bit of work, and it's not complete or stable enough for releasing yet, so I can't share it. You're in for a long road!


    Monday, January 22, 2007 4:11 AM

All replies

  • RayCar does a nice physics simulation, using the open source ODE graphics engine. It is C++, so you'd have to port both ODE and the sample code to use it with XNA.

    In general, what a car simulation does is:

    0) Update control input.
    1) Collision between chassis and world (typically, a box).
    2) Collision between wheels and world (typically, four rays).
    3) Create joints/constraints for the detected collisions. This includes a tire model with friction, rolling direction, propelling force etc, as well as a dampened spring for the shocks and struts.
    4) Integrate the rigid body of the car chassis using these joints.
    5) Repeat from 0.

    As there is currently no efficient 3D collision detection library for XNA, you'll have to write your own. I wrote one that does spheres, rays, boxes and heightfields, I'm trying to add meshes now. It's a fair bit of work, and it's not complete or stable enough for releasing yet, so I can't share it. You're in for a long road!


    Monday, January 22, 2007 4:11 AM
  • Thanks!

    I think I found something. It's called XNA Physics API and uses ODE!
    They dont have any tutorials how to use it for vehicles though

    http://www.codeplex.com/xnadevru/Wiki/View.aspx?title=XNA%20Physics%20API%20%28XPA%29
    Monday, January 22, 2007 4:31 AM
  • If this will be just 2D you can also use farseer (also on codeplex).

    Monday, January 22, 2007 3:48 PM
  • There is a book, while not XNA specific, that focuses on developing racing games. You may want to give it a look through. There's some pretty handy stuff in there.

    http://www.oreilly.com/catalog/1933097019/


    Thursday, January 25, 2007 6:45 PM
  • I have the book. Is it possible to convert the code in the book from C++ to C#?
    Thursday, January 25, 2007 8:30 PM
  • It's not going to be out for a while but this is the definitive XNA car game book.
    Thursday, January 25, 2007 10:43 PM