2.5D game actor facing the opposite of the mouse cursor position

Hello everyone. I am having a lot of trouble trying to make this behaviour.

I’ll attach you the blueprint that i made and a video link showing the problem.

I like the following method because it’s so universal and incredibly flexible:

  • imagine we create a virtual plane at the actor location, the plane is facing you
  • we then trace from the camera towards the cursor
  • at some point, the trace will intersect with the plane
  • we can rotate to face that point in 3d space

Image from Gyazo

If you print out the mouse position, you’ll see it has nothing to do with the X position of your actor. That’s the main problem.

I don’t usually work with flat D, so don’t have a good answer yet…

Thank you for the answer.
In this way my actor rotates in the z axis, not sure why. My actor should rotate on the y axis, to point the opposite
position of my mouse cursor

You’re seeing weird results because MouseX is a value between 0 and the maximum horizontal resolution of your display, it can be several thousand pixels if you’ve got many monitors…

Lets say we’re dealing with 1920x1080 only, though:

  • when the cursor is close to the left hand side of the viewport, you set Roll to 0, at far right you set the Roll to 1920 and anything in between. Roll is 360 degrees - essentially, it ends up tumbling the actor around many times as you can fit multiple 360s in 1920.
  • if you now work in actor world location, it gets even worse; what happens when the actor is at -8000; you get mouseX 1000 - 8000 and end up with -7000 roll and that’s like 20 full spins

Essentially, it’s what ClockworkOcean says in his comment, screenspace (mouse location) is very different from world space. We need a translation.

To visualise what I mean:

  • there is a plane at actor location we’re tracing against
  • the yellow arrow is the trace from the camera towards the cursor (projected into the world)
  • this trace hits the plane - that’s the intersection point
  • we then rotate the object towards that point - the green arrow

Hope this makes sense.

This is a great method if you want to rotate things at arbitrary angles but can’t afford / don’t want to rely on geometry.

Hello Everynone. Thank you for the answer, i did it and it’s working perfectly, i’m so happy that its finally working! Thank you so much!