1
$\begingroup$

in my game I have a painting behind glass and the glass is in the front side of the "painting case". Like this: Mona Lisa

All 3 objects (Mona Lisa, painting case and the glass) have the block property.

I am trying to detect only the painting case with a ray sensor without the x-ray mode. As I was testing it, I activated all the collision bounds of the objects as a box and the result is that the painting case's box covers the painting(Mona Lisa)'s and the glass's surfaces so I always got the painting case with my ray.

My question is : Does the ray detect surfaces or the collision bounds of the objects or an area near the surfaces, or what if none of the above? And if the correct answer is the collision bounds, should I have them "ticked" for this to work? If they are not ticked what does the ray detect(cause it returns the object, but the paint itselft )? And as a side-question : How does the margin attribute affect the collision bounds exactly? Is it visible somehow in the viewport?

$\endgroup$
2
$\begingroup$

Background

"Rays" are a method to detect if an imaginary line crosses one or more faces. That leads to the question: What faces?

In the BGE there are two kinds of faces:

  • visible faces (display mesh) and
  • collision faces (physics mesh).

These face types can but do not need to match. (Often it is better when there are less collision meshes than display meshes for faster processing).

Rays are part of the physics aspect. Therefore faces the physics would collide with are considered for hit detection.

Conclusion

I guess after this (hopefully understandable) explanation, you come to the conclusion that the ray will hit the shape defined by the objects Physics/Collision Bounds/Bounds

  • If it is set to Box, the physics mesh is a box where the display mesh fits in.
  • If it is set to convex hull, the physics mesh will span a convex triangle mesh around the display mesh (faster than triangle mesh processing)
  • if it is set to triangle mesh, the physics mesh will match the display mesh (creates the most processing overhead)

Be aware: quads are broken into two triangles. The triangles might not match the triangles of the display mesh as there are two ways to break a quad.

You can see the current physics mesh by enabling Main menu/Game/Show Physics Visualization (the green mesh when resting otherwise white lines). enter image description hereAttention: The visualization on a convex hull is not necessarily correct. I guess it is simpler to detect collisions than drawing a convex hull.

Answer

The ray detects the collision bounds your explicitly set up.

$\endgroup$
  • $\begingroup$ Thank you professor Monster! When you rotate the object during the game, the orientation of the collision bound, let's say the convex hull changes but not like it is parented. More like recalculated so it kind messes things up. Do you know if I am correct in this or I misunderstood the graphics. (Maybe it all sums up to the convex hull not being correct though.) $\endgroup$ – Lev Jul 22 '15 at 20:59
  • $\begingroup$ I'm not sure if I get what you mean. The physics mesh (convex hull in the example) rotates and moves with the object. This is independent from any parent-child relationship. The red box around the object is the bounding box relative to the scene. This is an helper to speed up identifying possible collisions and should not have further meaning to you. $\endgroup$ – Monster Jul 23 '15 at 9:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.