Download

"Find Look at Rotation" dependent on camera?

I am working on a top-down shoot-em-up in which the player object needs to remain pointing at the cursor. Thus far I have had a mode in which the player is always at the center of the screen, and everything works as expected when using the “Find Look at Rotation” function. But after entering another mode in which the camera is not centered on the player, it gets totally messed up. Moving the cursor now has a minimal effect on the rotation, varying by a small amount in either direction, which increases as the player gets closer to the point directly below the camera.

I can only conclude from this that “Find Look at Rotation” is somehow affected by the location of the camera. But this doesn’t make any sense to me; it’s supposed to just give a rotation to orient an object at the start position toward the target position. It should be fully possible to do that calculation independently of the camera. It should be possible to do without any camera at all, shouldn’t it?

Does anybody know what is going on here, and how I can make it work as expected?

OK, the problem was related to deprojecting the screen coordinates of the cursor to world coordinates. I was not using that function correctly, so my calculations only worked right when the camera was directly above the player object. What I ended up doing is making a vector pointing away from the camera through the cursor position, and calculating where that line intersected with the plane on which the player object exists. This gave me the correct position to look at.

Have you tried to use Get Forward Vector or Convert Mouse to World Location for calculations?

Edit: If those don’t work heres a tutorial I found https://www.youtube.com/watch?v=fOjAaskzquc