Sign in to follow this  

3D Racing Game - problem

This topic is 4689 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi I'm currently working on a 3D racing game. Cars and environment are modelled in 3D Max,they are exported to 3ds file and converted in conv3ds to x file. I put them in a LPD3DXMESH and use DrawSubset() method. And now I want to make cars interact with environment mesh (collisions, jumps, surface type checking, etc.) What is the best way to do it in your opinion? I know I have to check polygons around a car, get normals and calculate car's behaviour. But I have no idea how to do it or where to look for some hints. Help!

Share this post


Link to post
Share on other sites
What you are describing is far too complex for one thread. There is no one way to do this. Try searching the net for tutorials for 'terrain following' , collision detection', etc.

Myself, this link was very, very useful for me in creating a really fast Terrain Following algorhytm:(you'll need a good knowledge of basic math)

http://www.cg.tuwien.ac.at/studentwork/CESCG/CESCG97/melchart/

good luck.

Share this post


Link to post
Share on other sites
Here's a few guidelines from personal experiance, as always, what seems like a big project can be broken down into small, manageable sub-projects:

1) Collision
Collision detection is usually done against a different mesh from the one that is rendered. There are several reasons for this. The main one being that the information required for collision detection is different to that for rendering, although there is a small amount of overlap. The exact information is dependant on what you want to achieve.
So, in Max, create a second mesh that is a low poly version of your terrain - complex objects like trees, buildings and other static geometry can be replaced with simple boxes or other primitives like cylinders. You will need to somehow flag collision mesh polygons, one method is to colour the polygons - for a racing game, you'd colour the race track blue, say, and the areas around the race track red. Export this as you would for a normal mesh. Then, write a converter that takes the .X file and generates your own collision mesh data (there's a lot of data you won't need).
Finally, check the collision data you've created is OK by rendering a wireframe of the collision mesh over the top of the normal game screen. This is a useful debugging tool so it's worth the effort.

2) Collision Detection
Start off with a simple line vs polygon (a ray test). Use the debugging mode you created above to test this - create a camera that can be controlled by the user and do a ray test along the camera's look at direction. If you find a collision - draw a sprite or something - it should follow the terrain if you've got it right.

3) Cars
The next step is to put a vehicle into the system. Start off with doing a single ray test along the Y axis from the centre of the vehicle. Place the vehicle at the collision point (assuming the vehicle's origin is at the bottom). Next, find the normal to the collision plane and set the vehicle's up axis to this. Implement some simple controls - forward/backward/rotate and your vehicle should follow the terrain correctly (and tilt up/down hills).

Once you've done the above, you should have a good framework in which to experiment. There's not been any optimisation yet - the collision detection probably won't be that fast. Searching the web for things like oct-trees will give you ideas for sub-dividing the collision search (again, if you've got the wireframe drawing you can easily test that the data is OK).

Also, the next step for the car physics is to implement multiple ray test, one for each wheel, and then determine the position of the car from that. Then you could model the suspension to determine the position of the wheel relative to the car. And so on.

The trick is always to do things one step at a time. Break projects down into manageable chunks.

Skizz

Share this post


Link to post
Share on other sites
Thanks a lot! But,well, I knew it most of it already. You see my major problem is lack of practical experience, although I know waht to do (in theory) I don't know what functions to use (to do a ray check, get mesh polygon data etc.)

Anyway thanks. Maybe you'll check this post and help me to find the right methods.

Share this post


Link to post
Share on other sites
Starting with the ray test: Have a look at the Moller-Haines algorithm (an implementation can be found here). This is a good algorithm as it only requires division to be done when there is a positive intersection (division being slow wants to be avoided wherever possible). Create a simple application that draws a single triangle (no need to texture it or anything) and a single line. Allow the line to move (using the cursor keys) and then highlight the point on the triangle that the line intersects using the algorithm above. You'll need to convert the triangle defined by points A, B and C into three plane equations. The only downside to this algorithm is that it requires 12 floats to define a 3D triangle as opposed to the nine floats required to specify the vertices. Note that the collision data files don't need the vertices of the triangle, only the planes (for debugging purposes, you'd probably want to add the vertices to your collision data and then remove them when doing a release build).

Skizz

Share this post


Link to post
Share on other sites

This topic is 4689 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this