- Home /
Solved the problem by myself eventually
Making OnpointerClick event ignore certain colliders.
Hello,
I am using interfaces to implement pointer click and pointer up functionality for some objects in my scene. The game has a first person action camera following my player. The Interface works fine on all the objects except when the player's capsule collider gets in the way.
For example, if an object I want to click is slightly to the left of the player and very close, nothing happens when I click it because the clicks are hitting the player's capsule collider first. I am not saying that the object is obscured by the player, I am saying the player's collider is wider than the player model so it appears I am clicking next to the player character but I am actually hitting his collider. If i move the player a little more to the right I can click the said object.
I've tried putting the player on the Ignore Raycast layer but it doesn't work. How can I get the click event to trigger if my object is masked by another collider?
this may not be what you want, but have you considered making the player's capsule collider slightly smaller than the player itself. It's more of a work around. Otherwise you'll need to play around with the EventSystem and do a check for where the click position is before calling the action you want.
Hey, thanks for the reply. Yeah, I though about it, but the player's capsule collider size is set this way for proper interactions with what else is going on in the scene.
I think I will have to do it this way and adapt everything else to the change.
Thanks! :)
maybe try this, i used it when i had multiple UI objects purposely over each other https://docs.unity3d.com/ScriptReference/EventSystems.EventSystem.IsPointerOverGameObject.html
Answer by Esteem · Apr 03, 2019 at 09:04 PM
...I've tried putting the player on the Ignore Raycast layer but it doesn't work...
it does work, you're probably doing a tiny bit of it wrong. can you show us the code you're using for masking the player collider?
Hey, I figured it out. In the Physics Raycaster's Event $$anonymous$$ask I took out the Player layer and it works now. Thanks for taking the time to reply :)