Collision detection - Donuts 3D
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
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 >0 and gradient < 45 degrees then retard motion.
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.
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 >0 and gradient < 45 degrees then retard motion.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement