Hey. I’m trying to get the mouse cursors world position on the X-Z plane for a 2D game. I have the screen position already but I’m not sure how to convert that to a world position.
My first guess is to actually create a 3D plane on the same Y position as my player and raycast from my camera to it but…
A) This stinks of a workaround to me where there’s probably a simpler way.
B) I don’t know how to trace from my Vector2 mouse position relative to the camera along the camera frustum.
This is for a 2D platform game where I simply want my character to aim at the mouse cursor.
Any tips would be very welcome. Thanks for looking.
The Top Down Template project should give you an idea on how to get mouse position. You could also try creating a Blueprint Side Scroller project and migrating the MyController from Top Down into Side Scroller. Doing so allowed me to control the character by mouse clicking in the Side Scroller project instead of the default controls. Should be something to get you started.
To get the mouse position, you could try something like this which is connect to an Event Tick:
Thanks for the reply Wes. Gonna get on that now and try it.
I’ve tried using the Convert Mouse Location To World Space node which I would have thought is exactly what I wanted but the mesh doesn’t move to the exact mouse location. It moves towards the location but only gets a few units from my character and stops.
If you have any thoughts on my current setup (image attached) let me know. I’ll give your suggestion a shot now and mark this as answered.
Thanks.