- Home /
How to disable collisions just for the cursor?
Hello, I need to temporarily turn off the collision between the cube and the mouse cursor, BUT while maintain collisions between the cube and the player. I found this: Physics.IgnoreCollision(bullet.GetComponent(), GetComponent());
But the problem is that I have to give Collider, and the cursor itself is not an object in the game that has Collider.
How could this be solved?
Unity doesn't detect collisions regarding the mouse cursor by default, you're either using Raycast or On$$anonymous$$ouseOver to do that, just don't run that piece of code that checks that when you don't want to detect the collision.
In the On$$anonymous$$ouseOver () function, at the very beginning I have the 'if' responsible for checking whether the mouse is supposed to select the object - if yes - changes its color, etc. - if no -nothing happens. But still, when you try to interact with something behind this object, the game does not detect that it is trying to interact with it - as if the box collider still blocked it. Look at this screenshot:
The first cube is invisible and Im trying to click on the white cube behind it, but nothing happens. And I can not turn off the collision completely because I want it to keep blocking the player.
Oh, I misinterpreted you, I thought you meant disable the cursor, not the cube. I can't see the screenshot, but I think I know what you mean.
One idea is to simply turn off the collider and turn it back on when it is needed again, but it is difficult to do this on a large scale. Changing the layer temporarily to IgnoreRaycast works too, but it has the same issue.
You could also use Physics.RaycastAll for the cursor collision ins$$anonymous$$d, but the script that has the raycast would need to be told what it is looking for.