Archive 17/01/2023.

Simple collision check between any meshes

Marcin

Hi,
What is the simplest way to detect collisions between two any meshes? Without any physics, only detect collisions in every simulation step, with information which objects have collisions.
Is there any way to set distance (a margin) to detect a collision?

Thanks in advance,

Bananaft

Even If you don’t want actual physical interations, you can use Bullet for just the collision detection. And I belive that’s what you should do.

Marcin

Thank you for answer. I tried collision detection from sample 18_Characted_Demo. If I set SetUseGravity(false) for my objects and subscribe to E_NODECOLLISIONSTART then I have almost what I want. Gravity does not work, I have a collision notification, but Physics is still blocking me from programically move one object into another. How to completely turn off physics, leave only collision checking?

Eugene

Have you tried to mark your object as Trigger?
However, I don’t know whether the triggers are colliding with each other.

Bananaft

Trigger should work. If it does not, or you have some other motion related issues, you can also try turning on Kinematic mode for your rigid body.

Marcin

If I mark objects as Trigger, it is ok if I set setBox() for CollisionShape. But if I set SetTriangleMesh() for CollisionShape, and mark objects as triggers , then the collision notification will stop working. Turning on Kinematic mode for rigid body does not help.

Eugene

Triangle meshes and heightfields couldn’t be dynamic. Does other shapes work?

Marcin

Yes, other meshes work (sphere, capsule itd). So, is it not possible to do it with only triangle meshes (for example mushroom objects)?

Eugene

There are two shape types except trimesh (ConvexHull and GImpactMesh) that have model as input. Try them.

Bananaft

Why you need tri-meshes exactly? Can you give more specific info on what you are trying to do?

Is it two meshes like static level and some entity in it, or it’s several movable meshes?

Marcin

I need Tri-Mesh because i have one irregular body and several other U-shaped bodies. The first body is similar to the capsule, but it has a lot of irregular elements on the surface. I need to know when this first body is in collision with any of the U-shaped bodies, but I can not simplify the shape very much, I must have high accuracy. All meshes are static, I only programmatically change the position of the first object, but no object uses the mechanisms of physics etc. But now it’s ok, I set the first body as ConvexHull and the U-shape bodies as Tri-Mesh (I can’t set them as convexhull because it simplifies the model and fills the space) and it works ok. I have a question if I can somehow detect the closest distance to a collision? If there is no collision but it is close, how to check the distance?
Thanks in advance.

Bananaft

Remember that you also can use compound shapes if convex hull is not enough.

There is no easy way to get closest distance between two surfaces, I’m afraid. With convexes you can adjust collision margin one step at a time and see if it collides or not.

Marcin

I would like to try use GImpactMesh, is there any example how to use it?

Eugene

Nope, but there is no interface difference between Convex, Trimesh and GImpactMesh except shape type. You set the type, you set the mesh.

Marcin

But there is no GImpactMesh type in CollisionShape.
enum ShapeType
{
SHAPE_BOX = 0,
SHAPE_SPHERE,
SHAPE_STATICPLANE,
SHAPE_CYLINDER,
SHAPE_CAPSULE,
SHAPE_CONE,
SHAPE_TRIANGLEMESH,
SHAPE_CONVEXHULL,
SHAPE_TERRAIN
};

Eugene

I’ve added this shape type about a month ago. Use fresh master revision.