Projectile Rotation Towards Mouse Coordinates. {BP}

Hello everyone,

Working on a sidescroller game while I’ve ran into a problem with projectile rotation.

I’m trying to achieve projectile rotation from the location of the skeletal socket to the mouse location.

Pawn Blueprint

Skeletal Mesh Socket

Visual Diagram

Hopefully someone has better insight into my problem.

Try to use the node ‘Convert Mouse Location to World Space’ This will give you the location of mouse cursor in world space and also the direction. You can then calculate the relative rotation using this location and your charcters’s fire socket. Then you can use ‘Make Rot from Xvec’ to convert this vector to Rotator and use this as Projectile rotation

I will show an example below. Note taht this si not a solution to your problem. It just shows how to use this node.

Well I ended up finding a solution, there was a lot of issues especially since I’m doing networking.
Attached is my final rotation function for my projectile. Basically on the client I have to calculate the projectile rotation then on the server side spawn the projectile using the rotation that was set on the local machine.

Quick Note, the node get mouse position causes UE4 on the client side to crash.

Desired Rotation(Client/Server)

Great! I think I will try your method.

About the crash. Maybe its becuase the PlayerIndex is wrong? If you always set it to 0, you always end-up with the first player’s player controller.

I was thinking it could be that, because the call was from the server side of things.
Instead I decided to have my MousePosX and MousePosY set from the Mouse Y event.
Also I used Ramas Extra Blueprints to get the mouse position on the screen.

Mouse X/Y Function
Also Returns an Anim Offset for my Character Animation.

Still, you are using ‘Viewport Get Mouse Location’ with PlayerController_0 as the input always. What if this gets executed in second players PC (he cannot access the viewport of Player0). I think you can get a reference to the Pawns’s camera and use ‘get Owning Controller’ to get the right controller. I am not 100% sure, but try that and see if it works.