playMaker

Author Topic: [SOLVED] Raycast from camera to mouse position?  (Read 1178 times)

Breadman

  • Full Member
  • ***
  • Posts: 185
  • Derp
    • View Profile
[SOLVED] Raycast from camera to mouse position?
« on: May 10, 2017, 09:01:36 PM »
I'm trying to detect which game object (if any) is under the mouse, and use that information for other FSMs. But I can't seem to get my ray to move "towards" the mouse - instead it just shoots off from my camera in a random direction.

I track the mouse position's every frame and supply this information to the raycast action's "direction" field, but all this does is cause the ray to rotate randomly as I move the mouse (img 01). I did some reading about "screen to world point" - but when I convert the mouse position into a world point, and then use the world point as the ray direction, the ray just stays frozen, even when I move the mouse (img02).

Totally stumped here, hopefully I'm just setting this up incorrectly? Grateful for any guidance!

« Last Edit: May 10, 2017, 09:42:24 PM by Breadman »

tcmeric

  • Beta Group
  • Hero Member
  • *
  • Posts: 758
    • View Profile
Re: Raycast from camera to mouse position?
« Reply #1 on: May 10, 2017, 09:29:12 PM »
Maybe I am misunderstanding what you want to do, but have you tried the mouse pick action? Set it to everyframe. It will return the mouse location and any game objects it is hovering over.

Breadman

  • Full Member
  • ***
  • Posts: 185
  • Derp
    • View Profile
Re: Raycast from camera to mouse position?
« Reply #2 on: May 10, 2017, 09:42:08 PM »
Wow, I feel dumb. Mouse pick was exactly what I needed. I've always used mouse pick event, which requires you to specify an object first, so I must have overlooked Mouse Pick thinking it was the same action.

Thank you!!!