Best method to track movement, detect collision with walls in 3D?

Started by
2 comments, last by Vorpy 17 years, 5 months ago
Well, I know how to make a 3D environment, and I'm tossing some ideas around in my head about how to provide interaction in the environment, but I'm guessing what I'm thinking is far from the most efficient way to do it. Right now, I'm primarily concerned with walls. What's a good way to go about it? edit: I'm going to get a bunch of links to other topics, aren't I? :p
Advertisement
Quote:Original post by BrknPhoenix
Well, I know how to make a 3D environment, and I'm tossing some ideas around in my head about how to provide interaction in the environment, but I'm guessing what I'm thinking is far from the most efficient way to do it. Right now, I'm primarily concerned with walls. What's a good way to go about it?
It sounds like you already have something in mind. Perhaps you could describe your idea, as it would be easier to provide feedback that way.

Beyond that, it depends on the context, but discrete sphere-polygon collision detection and response can work well in a variety of situations, and is relatively straightforward to implement.
Some interactions are easy to model than others. It's really easy to check to see if two spheres are colliding, for example, because you just have to check the distance between their centers. Walls are a little more complicated because there are many more collision cases - your player can hit the corner of the wall, the center, the top, etc (they could only hit a point right in the middle of a sphere... they're all right in the middle!).

If you just want a simple wall test, you might want to restrict yourself to walls that are aligned with the x, y, and z axes, because the math ends up having a lot of nicely cancelling zeroes and you can ignore rotation, etc. The basic strategy is to keep information about how wide, tall, and long walls are, and where they're centered. With that information you can deduce what other objects are in the same space, and from there decide what to do (e.g. bounce the player off the wall).

If you want to do more complex physics work, it may be worth it to learn to use a physics engine. The ODE is a popular one that I've been working with for a couple months, but there are several others around. Integrating a physics engine into your project can be very complicated, though, so I really suggest thinking about simplifying down to the axis-aligned walls I mentioned.

Good luck~
--Riley
For a large and/or complicated environment, you'll want some sort of space partitioning scheme so you can find which walls are near the moving objects without having to go through the entire list of walls. Then you just do the collision detection with those walls. Octtrees and binary space partition trees are popular choices for this purpose.

This topic is closed to new replies.

Advertisement