Page 1 of 1

Mouse Selection Trouble

Posted: Tue Mar 24, 2020 7:21 pm
by AlexNerd
Hi there,

I'm trying to make it so the player can use objects by clicking on them, and I've set input to "Mouse 0". I've tried to start a conversation on the use of both a 2D and 3D object, both of which have colliders and a "usable" component.

From what I can tell the raycast is hitting the 3D object, but it's not working and I'm not sure why. Also, is there any way to use the raycast with a 2D sprite? Thanks.

Re: Mouse Selection Trouble

Posted: Tue Mar 24, 2020 8:48 pm
by Tony Li
Hi Alex,

Assuming you're using a Selector component, here are some things to check:
  • Selector's Select At dropdown is set to "Mouse Position".
  • The Layer Mask is correct to pick up the Usable that you're trying to detect.
  • Max Selection Distance is high enough.
  • For 2D:
    • Select Tools > Pixel Crushers > Dialogue System > Welcome Window. Make sure the 2D Physics checkbox is ticked.
    • Set your camera to Orthographic.
    • Set the Selector's Run Raycasts dropdown to "In 2D".
    • If you're mixing 2D and 3D, just use 3D colliders for everything.
If you're running raycasts in 3D and you tick the Selector's Debug checkbox, it will show what 3D objects it's detected:

Image

In the Scene view (on the left), the yellow line is the raycast from the camera. It detected the NPC, Private Hart, so it drew a green sphere at the detection point.