IRaycastable on custom meshes

I have a question about setting custom objects as IRaycastables. In my game I have floating cube objects and a script called “QuestTarget” which I created. QuestTarget implements IRaycastable.

Floating Cube: It is 6 quad faces oriented to line up with the faces of a cube. I did quads instead of a cube because I want to individually texture each face of it (or at least 4 of the 6 that I care about). Here’s where I run into some issues.

The parent object floating cube is an IRaycastable because it has the QuestTarget script on it but the objects that get hit with the Raycast are the children and they are just plain quads.

For IRaycastable to work it seems I need to put QuestTarget on each face (it would require some changes to my script but doable).

But putting a QuestTarget script onto each face seems like a hack. Is there a smarter way to do this?

image
image

 public class QuestTarget : MonoBehaviour, IRaycastable {

        public CursorType GetCursorType()
        {
            return CursorType.ClaimQuestItem;
        }

        public bool HandleRaycast(PlayerController callingController)
        {
            if (Input.GetMouseButtonDown(0))
            {
                ClaimQuestItem();
            }
            return true;
        }
}

You could put a box collider on the parent object, and no colliders on the child objects.

As soon as I saw that I immediately felt dumb. Of course. Obvious solution.

You could also just texture the cube with the UVs set up correctly. Your friendly neighbourhood renderer will thank you

1 Like

I was waiting for someone to say this. :slight_smile: Honestly UV maps seem so like so many extra steps for what I want to do. I need the ability to dynamically set cube faces so writing code to create UV maps on the fly seems like a lot of work for unclear benefit.

Yes, for dynamic cube faces, a trip to Blender for quality UV Mapping won’t cut it, unfortunately.

Yes, one or two cubes is not going to make a difference, really. It just immediately jumped out at me because I’ve recently been working to optimise scenes with thousands of models and I’m dreaming of combining meshes and creating texture atlases already.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms