I’m trying to create an invisible game object that I can place within a level to determine when a player is standing in a particular spot - i.e. when the player makes contact with this invisible object, it executes a script that “does something” but has no effect on the player in terms of stopping them etc.
What’s the best way to approach this?
colliders are meant to do just that. you can make an empty game object and attach a box collider to it and activate the “is trigger” option.
when the player touches that box the OnTriggerEnter function gets called which you can use to execute your custom code
I’ve tried that, but the box collider stops my player - i.e. the invisible object acts as an obstacle and the player can’t move past it.
make sure the “is trigger” option is activated on the collider, this disables all physical collisions
Yep - definitely turned on. I have raycasting on my player that detects obstacles in front of the player and prevents them from moving. Would a raycast hit a collider that is set as a trigger?
OK - it’s working. I had to set the box collider’s “thinkness” (Z) to 0. Is that weird? Seems weird.
Cancel that - still doesn’t work. Just appeared to because I could move up closer to the object and actually trigger my code. It still blocks me. Must be the raycast thing.
if the raycast is the problem, you can add the collider to the layerMask of the raycast. i don’t think i can explain it any better than this article:
feel free to ask if you are still having problems
Thanks so much mate! That’s the answer - I’ve put a layer tag onto my “building” and I’m raycasting just on that layer. The invisible collider now works without interfering with the player.
I really appreciate the help!