How to fire projectile from skeletal mesh socket to crosshair in third person?

I have been using the third person template so far, and I’m trying to get the player to shoot at the mouse location. Think of any third person/over the shoulder games where the player can fire weapons (Last of Us, Watch Dogs, Infamous, etc). I’m close, but the aim is off by a bit. Here’s what I’ve done so far:

  • I’m using Owen from the content examples (the one where you possess him) but in a third person template. I imported that pawn and am using him instead of the blue-ish mannequin guy.
  • I am using the LeftHandSocket as the projectile spawn point in Owen’s skeletal mesh.
  • Projectile velocity is x = 1, y = 0, z = 0 with no gravity.
  • Crosshair at center of viewport.

I spawn the projectile by left clicking in the character blueprint at the socket’s location + a forward vector and at the rotation of Get Control Rotation node. The projectile is will travel in the same relative direction the camera is facing, and hit somewhat close to whatever the crosshair is pointing at but a little to the left. I feel like I’m missing something simple, but I’ve watched all of the tutorials I can find. I’ve looked at all of the sample projects like the Shooter Game, but that’s in c++. I’m doing this in blueprint only.

I hope someone can point me in the right direction.

I made some headway and think I have it figured out. If there’s an easier way or more efficient way, please post it!

I did all of this in the Third Person Template, but I used Owen from the content examples (I migrated him from Content Examples). It would probably work with the default mannequin guy as well, but I haven’t tested that. Here’s what I did (sorry if it’s grainy):

The event to in the image is just the Left Mouse Button (I have it set in the project setting’s input panel as shoot). The projectile I have set up is the same from the first person shooter template (velocity only in X direction, initial speed of 2000, but with no gravity so it will fly straight).

Basically, you have to do a trace from mouse world location to 20000 units forward. That 20000 may be way too big, but it will ensure the trace hits something. If the trace hits nothing, the projectile will fire at the last item that was hit. Then using the location from the break hit result, find the look at rotation between spawn point of projectile and this hit location. I have my crosshair in middle of the screen by the way.

When you spawn the projectile, the location is the your spawn location you need to set up before hand and the rotation is the result of the find look at rotation node. For the spawn position, I spawned my projectile at the desired location * 100 units forward. My spawn position is Owen’s RightHandSocket. Note that the 100 forward is not simply 100 units in x world location, but 100 units forward from whatever direction you are facing.

To actually see the line trace, select an option from the drop down box in the Single Line Trace by Channel node.

I hope this helps someone!

This interests me! Is there a way you could upload a sharper/larger image? it’s just to grainy for me to make out. Cheers!

Hello,
ca you help me by uploading a larger image, please.

There is also a get socket transform function that allows you to choose what socket you want to spawn from :slight_smile:

Hope this helps