Jump to content
  • Advertisement
Sign in to follow this  
Heelp

Need a very simple collision detection for walls. ( 3d )

This topic is 683 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

Guys, I need a way to detect simple collision with walls. My map is pretty basic. All the floor is on the same height and I have very simple walls that I need to collide with. 

 

Two ways come to mind and I'm wondering what's better.

 

1st - Put one camera watching my hero from above. Use this camera to render the depth values in front of the hero in another framebuffer. If the depth values in front of the hero are less than the depth value of some fragment from the hero, then there is a wall in front of him.

 

OR

 

2nd. Make AABBs for every wall. The problem with this is that every time there is a turn, I need to divide the wall into separate meshes and find the AABB for that mesh, because if the wall is like this:

 

(top view)

          ____

         |     |

   ___ |     |

 |_______ |

 

And I count these two rectangles as one mesh and find the min and max x,y,z of the two figures, the AABB is going to be this:

 

(top view)

 ________

 |             |

 |             |

 |______ _|

 

And this is very inaccurate. That's why I have to make a new mesh every time the wall turns left or right.

 

What to choose?

 

I hope someone understood something from this very bad explanation.  :lol:

Edited by codeBoggs

Share this post


Link to post
Share on other sites
Advertisement
Can you not just test collision between a box (your player) and triangles (your wall meshes).

I tend to use the fast triangle-box overlap test from Tomas Moller for things like this.

http://fileadmin.cs.lth.se/cs/Personal/Tomas_Akenine-Moller/code/tribox3.txt

There are other fast intersect tests here too such as tri-tri and ray-triangle.

http://fileadmin.cs.lth.se/cs/Personal/Tomas_Akenine-Moller/code/

Share this post


Link to post
Share on other sites

If the reason you can't use an AABB for your walls is that the walls have corners in them - i.e. they are concave objects - you could split those walls into 2 convex walls, each with its own AABB.

Share this post


Link to post
Share on other sites

Is this only for the character, or also for projectiles, etc? Are your walls always perpendicular to the ground? If so then you can do circle-vs-edge, since your problem would effectively be 2D. If your geometry is static then you can tessellate it into regions beforehand and skip the broad phase entirely, since each region will know exactly what walls are within reach.
 
Check out http://www.metanetsoftware.com/technique/tutorialA.html and http://www.metanetsoftware.com/technique/tutorialB.html to get some of the basics and gather a bit of vocabulary.

Share this post


Link to post
Share on other sites

Guys, thanks a lot for getting me started. Will post later if there is some progress.

Edited by codeBoggs

Share this post


Link to post
Share on other sites

do you have an underlying map that tells you where to draw walls? or is it just a list of triangles / quads/ renderables?

 

almost every game i've done used an internal map (usually a 2d array) to represent the game world. it said where to draw the graphics and was also used for collision checks.

 

in my current project, not everything is a map. many of the maps are implemented as sparse matrices (IE a list), not 2d arrays. terrain chunks are just ordered lists of renderables.  what i do is generate a 2d collision map at some desired resolution, and use that for collision checks.

 

it often turns out one data structure (such as 2d arrays) is best for fast collision checks, but some other type of data structure (such as renderables list - oct-tree, etc) is better for fast graphics.

 

so you keep two copies of the info, one in each type of data structure, and use the best data structure for the job at hand.  data oriented design.  how the data is used determines the best data structure for each task that uses the data. odds are different tasks (like rendering and collision checks) may have different "best" data structures (such as an ordered list of  renderables for terrain chunks, and 2d collision maps).

 

while it may be less efficient from a memory use point of view, its WAY more efficient from a clock cycle use point of view.

Share this post


Link to post
Share on other sites

Yes, I was about to say that if it's axis aligned and regular in shape an array would probably work.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!