playMaker

Author Topic: Follow Mouse and trigonometry  (Read 944 times)

Evaldas

  • Playmaker Newbie
  • *
  • Posts: 21
Follow Mouse and trigonometry
« on: January 30, 2022, 08:10:16 AM »
Hello, wanted to ask for help implementing Follow Mouse action. Thank you for your time to read this long post :)

I want an object to follow mouse every frame in 3d world space. The camera is RPG type view from above at an angle. I have walls and buildings in the level.

- Mouse Pick action - gets great following results, but bumps into walls and other objects and throws off the mouse in unexpected positions. Tried to isolate movement by adding layer mask, but still doesn't work smooth and throws arround.
- Screen to World space action - Also works, but the mouse is very floaty, the further the object goes into Z space, the more of a mouse movement you need to make.
- Mouse Follow action - the follow feeling is amazing, object always exactly on the mouse. The problem is "Distance to the camera" parameter, which in my camera view angle makes that the closer the object is in Z space, the lower it goes into the ground because it tries to maintain the distance to the camera.

So I figured I need to always calculate the distance to the camera so the object stays level with the ground, but can't solve the math here... or maybe the answer is much more simple?

Evaldas

  • Playmaker Newbie
  • *
  • Posts: 21
Re: Follow Mouse and trigonometry
« Reply #1 on: February 01, 2022, 09:18:13 AM »
bump :)