Top Down Player look at Mouse

i try to make a top down shooter and my player should look at my Mouse.
I tested many things and nothing works.
How could i do this?

There’s a couple ways, but considering the fact that DeProject function isn’t already exposed to blueprint, this one seems simple enough for you, in the essence:

Assuming the player is always in the middle of the screen, first get the mouse position and subtract it from the center point of the screen (can be calculated easily by getting the viewport size first), now you have a vector showing you the rotation you need in 2d, convert it from 2d space to 3d and it’s done. (again, assuming the camera doesn’t rotate, the conversion is gonna be straight forward.)

I tried Farshad12’s approach at first as well, but that didn’t work for me. Maybe I just did it wrong :D.
This however did (the RayPlaneIntersectionPoint thingie is a Macro, just in case).

Thanks Farshad12,
It works a little bit better than my atan2 version (i think the atan2 version only goes for 2 dimensional space…), but also not good.
divi´s solution doesnt work but maybe i make something wrong. The macro is the same as on the picture, i double checkted that, but im not really sure how to use the output?
I break the intersection vector and make a rot out of that, but only with the yaw parameter, so my character only rotates on this axis and then i connect it to the SetWorldRotation.
Should i do something else?

Was the 2 assumptions that I made true for your case? Because if not, the solution either won’t work at all, or it needs to be modified accordingly. Also what was the problem with it exactly?

I would suggest that regardless of which way you choose to proceed with this, send your start and end points (the one that you calculate, plus anything else that might help you visualize the problem), to your hud blueprint, and draw debug lines/spheres so you can see clearly what your implementation is actually doing. That way it’s at least two times easier to see what’s wrong with it, if not more.

Yes they are true, the problem is that i dont know how to use the output vector from the subtraction right, currently i make a rot, but connect only the y with the yaw, because it should only rotate on this axis. And it seems that my x coordinate from my mouse doesnt effect the rotation. (I think because i dont use the x value form the vector)

Then you have to correct that, because there’s no way you can get a rotator from only one component, you’re gonna need at least 2 in this case. There’s a couple ways to calculate this rotator, though I’d suggest using a "FindLookAtRotation, with the 2 points I described as STart and Target inputs. Make sure to have 0 for the Z of both points before you link them to the inputs.

Also this might give you a different rotation by an scale of 90 degrees, depending on which corner of your screen represents 0,0,0 of the world, so if it wasn’t the one rotation that you need, just rotate it by 90 or 180 degrees and you’re good to go.

Thank you sooooo much! You rescue the project :slight_smile: I searched for a function like FindLookAtRotation since 3 Days! Thank you man :slight_smile: