Sign in to follow this  

collision methods

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

To start this off I'm working with the threejs library. Currently what I'm doing for a player controller/ground collision is raycasting downwards to see if im on the floor. Now I loaded a tree i made in blender using the sappling app, and im having some collision problems. First off it lags like shit because of how complex the mesh is ( the leaves & all the tiny branches ). How can I simply my collision so that it only checks collisions on say the larger branches, i dont care if you fall through most of the tree.

 

I'm really struggling with how to handle things after i get collision data. I know how to check collisions but im having huge troubles making things practical with a character controller. Is using a raycast for the ground the best method of handling a player/mobs/etc? I'm not looking for super complex collisions for my game but i want everything to collide properly. If someone could help me adjust my methods id be so greatful

 

Any help is appreciated

Share this post


Link to post
Share on other sites

Tree.js isn't designed for collisions. It is desingned to render meshes.You shouldn't use it for (almost anything else).

Typically you will have a separate mesh for the collisions that is build specifically for collisions(expecially for complex scenes). The data layout for rendering is just different from the one needed for collisions, and usually rendering meshes are much more detiled compared with collision meshes.

 

It is not possible to implement proper collision detection(for your case) by just using raycasts(ok maybe it is with enough raycast you could implement something 'usable'). You will need to implement something (or get a library) that can handle Sweep/Intersection test between different object.

 

The most common solution for your case is an ellipsoid/capsule vs mesh test (if I understand you problem correctly).

Edited by imoogiBG

Share this post


Link to post
Share on other sites

axis aligned bounding boxes is one of the most basic forms of collision detection.

 

a tree might be represented by a single large box, or one for the trunk, and a few more for the larger branches.

 

if more precise collision detection is desired, there's a whole bunch of methods to choose from, with varying degrees of accuracy and complexity. you could probably spend days googling and learning about all the possible methods.

 

the general rule of thumb is to choose the simplest method that's sufficiently accurate for you particular needs.

 

for ground collisions, i compare the altitude (y) of an entity vs the altitude (y) of the ground, as given by the heightmap at their location.

 

jumping gives an entity a y velocity upwards, and flags the entity as airborne. while airborne, normal controls don't work. x and z movement is based on x and z velocities when the entity left the ground. y velocity is reduced by gravitational acceleration, then applied to the entity's y position.  then the entity's y is compared to the ground's y to see if they landed. if they did, the slope of the ground is checked to see if they land (a relatively flat slope) or bounce off (a steep slope).  either way, y velocity downwards determines damage taken from contact with the ground. when they finally land and don't bounce, airborne flag is set to false, and normal movement resumes. 

Share this post


Link to post
Share on other sites


Currently what I'm doing for a player controller/ground collision is raycasting downwards to see if im on the floor. Now I loaded a tree i made in blender using the sappling app, and im having some collision problems. First off it lags like shit because of how complex the mesh is ( the leaves & all the tiny branches ). How can I simply my collision so that it only checks collisions on say the larger branches, i dont care if you fall through most of the tree.

Graphics meshes are almost always the wrong choice for collision detection.

 

Also, these tests are generally done in multiple phases.

 

The first thing is to break it down into a better spatial grid and better physics objects, both broad pass and narrow pass.  Since you talk about "the ground", you might consider using general footprints for each object. That makes a 2D world representation that is much faster to check against. Each object gets an associated footprint, preferably modeler-made but potentially automatically generated based on AABB. Then all of this is typically stored in a data structure called a loose quadtree. If you absolutely cannot reduce it to a 2D test, use a 3D spatial tree such as a loose octree; this is both larger and slower than a 2D representation, only use it if you must.  Then your modlers also provide a second, simplified collision shape. For characters it is often a capsule or snowman of spheres. For other objects it is often 1-3 boxes or 1-3 spheres or other simple shapes. These are best when modeler provided, but can be built through AABB if you must.  Very rarely you will want to use the same mesh for rendering as you do for collision, but this should not be the normal case.

 

For your first collision pass. For a collision test you query the loose quadtree to see if footprints overlap with your test, usually it is a box-to-box test or a box-to-circle test. In most games the quadtree quickly returns that there are zero other boxes in that area, and you are done. Sometimes there will be a small number of potential collision objects, so those make it to the next pass.

 

The second pass, if there were any results from the first pass, is to test against the higher detailed models. Instead of taking place on the ground's spacial tree, this can take place as a 3D test if that is needed for your game. That pass should use the simplified model of 1-3 spheres or 1-3 boxes or similar, or in extremely rare situations, use the more detailed mesh. 

Share this post


Link to post
Share on other sites

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