#### Archived

This topic is now archived and is closed to further replies.

# Collision detection - Donuts 3D

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

## Recommended Posts

Hi, a while back I downloaded the directx 8.0 sdk and used the Donuts 3D sample to create my own game, Dark Mantra (get the game and source at http://www.angelfire.com/games4/glensoft/ but bear in mind it''s a bit old and I''m much better now generally lol). I loaded my own .x file and set the hilliness of the terrain to flat. The collision detection was achieved by a set of conditional statements, like so if (PositionOfShip > Top) { SetReverseMomentum(); } However, I''d like to use the sample to create a game with a character inside a cavern, so I can walk up and down slopes etc. I really don''t think using conditional statements is the best way to implement collision detection, so what would be best? if (witisism == !witty) return to_hole

##### Share on other sites
Well... you could still use conditional statements, but your conditions become a lot more varied.

For example, instead of testing for out of bounds, you''d be testing for movement against a gradient. Then you''d have to say something like:

If Gradient > 45 degrees, stop movement.

Alternatively (and much better imho), you''d use the normal of the terrain that the object is on to apply some proper physics to the object. This makes it much simpler because every frame, you''re just adding/multiplying the object''s delta by some factor of the normal.

And as for detecting the normal (or even which part of the terrain the object is on), just use a ray-intersect-triangle check, and if you get a collision, you can work out the normal.

Learning to fly is easy, but as a tortoise, the landings are really rough.

1. 1
2. 2
3. 3
4. 4
Rutin
12
5. 5

• 26
• 10
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633694
• Total Posts
3013378
×