Skip Navigation

Is there any way to get ray intersections with meshes that don't have collisions?

So far (outside of somehow adding it into Godot via C++ myself) this doesn't seem possible but wanted to ask to see if i maybe missed something.

The most i could find was this issue and a couple of related ones.

My specific use case would be for drawing bullet holes onto meshes (via decals). Ideally also being able to determine the texture used on the faces of the meshes that are intersected (to determine an appropriate decal to use).

Having everything that is possible to hit duplicated as a static body or area seems excessive to me. Since the only data required for ray intersection should be the transform of the meshes faces/edges/vertices etc which i would think are already contained in the mesh itself?

Failing being able to make intersecting a ray with meshes work i will probably try experimenting with using areas. They seem the lowest performance cost out of all the options the existing ray cast can detect. I would still end up with most of the games geometry being duplicated though, once as actual meshes and once as collisions for all the areas.

19
19 comments
  • Alternatively if you get the mesh by using the collision shapes you can iterate on the mesh's surfaces and use godot's geometry class to check for intersection. If you get a reference to the mesh you can use get_faces method and Geometry class's ray_intersects_triangle method. This is a very manual method and not very flexible regarding node setups. It is also not very performant.

    • Oh i guess this is exactly what i was asking for XD. Although im probably not going to try it since always needing to place the relevant meshes in the same places relative to the collider does seem like a pretty strict requirement like you said.

  • I might be wrong but decals dont really care about collisions so you can just spawn a single decal regardless what it hits. If you really want to use different decals for different materials you can put them on different layers and spawn multiple decals on those layers. This works for static things. If you want decals on dynamic things you need to keep track of those objects Im afraid.

    • If you really want to use different decals for different materials you can put them on different layers and spawn multiple decals on those layers.

      Ooh, yeah that might be an option, ill keep it in mind when i get there, thanks :D.

      I might be wrong but decals dont really care about collisions so you can just spawn a single decal regardless what it hits

      Ive already been using a single decal to begin with and i'm having problems that being able to get ray intersections with meshes could solve. The decals need to be close to the mesh they are supposed to be projected on to look right. Otherwise they seem to fade with distance.

      For example here:

      The bullet is colliding with a triangle shaped collider that goes over these small stairs since that is more convenient and simpler for collisions with the player. But because the collision is simplified compared to the stairs actual mesh the decal can get placed far away from the mesh and not show up or only show up in some places.

      If i can only get ray intersections with colliders i'd have to create a much more complex collider that matches the stair mesh much closer to be able to place the decals closer to the mesh. But creating that many colliders that have no other uses besides this one seems like a waste. If i could get ray intersections with meshes directly i could just use that to determine where the decal should be located.

  • I'm having trouble picturing the problem. Are you trying to have a bullet leave multiple decals in it's path? Or decal non-colliders?

    Maybe you can do something with collision layers and assigning the colliding objects to groups that determine the texture of the decal?

    • It seems op wants to have areas that can't be reached not have colliders for performance, but still wants his bullets to be able to register hitting them for placing a decal on the collision.

      • Yeah this, although i should maybe clarify that the "bullet" is not a object/scene that has a position, i just perform one raycast to determine where it lands.

        Also its not just about areas that cant be reached but very small "detail" things as well. Eg.: i might want to have bullet holes appear on the leaves of a plant but other than placing the hole on them the leaves don't need to interact with the bullet or the physics system in any way. So creating an area or physics body just for this purpose seems like overkill.

19 comments