playMaker

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

Breadman

  • Full Member
  • ***
  • Posts: 185
  • Derp
[SOLVED] Raycast from camera to mouse position?
« on: May 11, 2017, 12:01:36 AM »
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 11, 2017, 12:42:24 AM by Breadman »

tcmeric

  • Beta Group
  • Hero Member
  • *
  • Posts: 768
Re: Raycast from camera to mouse position?
« Reply #1 on: May 11, 2017, 12:29:12 AM »
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
Re: Raycast from camera to mouse position?
« Reply #2 on: May 11, 2017, 12:42:08 AM »
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!!!