PhysicsRaycaster not working when cursor is locked
Hi,
My FPS project uses the inputSystem exclusively (for reasons I'm not going to discuss). This means I can't use OnMouseOver events etc, to detect when a user is looking at object that it can Interact with.
I added a PhysicsRaycaster to my camera, and my game objects implement the IPointerEnterHandler and IPointerExitHandler interfaces.
This works fine when the cursor is NOT locked, but as soon as I lock the cursor my gameobjects don't seem to receive those events anymore.
So how can I make this work when the cursor is locked? If not's possible, where can I report this a bug?
If you lock the cursor to the screen, I think it's fixed at the center, so whatever ray you cast using the mouse input position or watever events you have with the mouse pointer, will always be from the center of the screen. Maybe that's why it only works if the mouse is not locked. Try constraining the mouse to the screen, rather than locking it. Maybe that solves things
@mf41z Can I fix the cursor to the middle of the screen using a constrained cursor? This is a first-person perspective game, I don't want a moving cursor at all. Seriously, I can't be the first one who stumbles on this issue?
Let me understand better what you're trying to do. So, you're raycasting from the camera to the mouse pointer, right? for what purpose, specifically? Do you need to select objects with your mouse input? Or shoot at something?
It's a first person perspective game (not a shooter, more like an adventure game). I locked the cursor, and created a hud with a marker in the center of the screen (this is just a visual indication for the player). If the mouse/center hits an a gameObject that is "interactable" something should happen. With the old inputsystem this was easy: I could use the OnMouseEnter-events etc.. but those don't work with the new InputSystem. If you want an example of the kind of gameplay I aim for, take a look at "Tex Murphy: The Tesla Effect". I there is way to keep the cursor centered at the screen without locking it, that would solve my issue (then I won't need the hud either, I can just use a custom texture for the cursor). But I don't think that's possible.
Your answer
![](https://koobas.hobune.stream/wayback/20220613051713im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
[fixed] My physics.raycast vision doesn't work as I expect it to, and I don't know why 2 Answers
Raycast detecting colliders issue w/ image depicting problem 0 Answers
Get object under IsPointerOverGameObject() 0 Answers
How can I change completely the scene? 1 Answer
Trying to get script to receive input from EventSystem 1 Answer