Circle trigger-area that follows the player (Best Method?). [Solved]

I have been thinking of this issue for a while. What I’ve been looking for is a way to create this trigger around the player that follows him/her (obviously easy way is to parent it, this I know).

What I do not know is how to make such an object in Unity. I can easily create an empty game object but it’s in the shape of a box not a circle, and I would much rather avoid having to use a sphere because of what I want this trigger do. Having a sphere would create some problems for me.

Is there some sort of way to create maybe an 8/10-sided object in unity, have it with no material (so it does not appear in game) and make it so that when my mouse is inside the trigger it does something different than outside the trigger?

Honestly I am not looking for any script, I am wondering if this is the best method or if I am making it over-complicated and there is a simpler way to do it. (Such as detecting on a plane how far the mouse from the player, and if it is a certain distance from the player it can change what a left click does).

I would like to figure out the scripting myself. Pseudo-code is fine as long as you do not enter parameters for me and let me figure it out by using API.

If you can’t use a combination of box colliders for this…

You need two things, a Mesh and a MeshCollider. The easiest thing is to import a 3D mesh model and attach a MeshCollider to it. If you want to generate the Mesh on the fly, then get to learn the Mesh class and how to wrap triangles!

I’ve never used it, but you can probably use OnMouseOver() or something similar to know if the mouse is over your collider.

1 Like

Ah ok I was thinking I was just going to have to make a custom mesh. Where would I find some kind of tutorial for making an invisible mesh? (I guess that’s one that technically does not render).

Just make sure there is no MeshRenderer on the GameObject and nothing is ever visible.

You can still have a MeshFilter on the GameObject, with a MeshCollider, but nothing is getting rendered. The Mesh is used for the physics only.

2 Likes

Yep. Use a mesh collider of whatever shape you want, though preferably one that’s convex and almost certainly one with less than 255 verts (or faces? I can’t remember). As Garth says, you don’t need a mesh renderer. What you do need is a mesh collider and a Rigidbody. Set the collider to be a trigger, set the Rigidbody to be kinematic and ignore gravity.

You can make the mesh you need in something like Blender pretty easily, by the way. You can probably just spawn a default cylinder with the right parameters and export it as-is, in fact.

2 Likes

Thanks a lot for a push in the right direction guys. I feel like meshes being used for triggers are something that not a lot of tutorials touch up on even though I see a lot of practical application for it in nearly every game type. Maybe that’s just me not searching the right places.

Y’all cleared up a lot though!

3 Likes