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
0651019bcadbbd1fc3bb6092ac2d39d9b255e5d5.jpeg

Visual Diagram
fa3198a0f180dbf31df408b05c40abb2023b5f47.jpeg

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.
fa138d9c1b991e3e651d4a20d60b86da167fb7d9.jpeg

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)
bb32f3b4bce239963de03e20e6c242b233dcecb0.jpeg

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.
c00cf5c720876a8dd6d0fe3a679b40a47d1b5d82.jpeg

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.