Download

How to get the projectile to fly to the crosshair?

hello all

im having some trouble figuring out how to get my projectile that spawns from my weapon barrel to fly towards the crosshair and not exactly where the animations like idle and sway influence the guns direction. any suggestions?

please note im using a template called fpsm the majority of the blue print code is the creators

Check this thread, maybe it will help.

I’m not sure if that works as I haven’t it tried myself, but you coul try it. It’s simple math you can easily make a test.

APawn::GetPawnViewLocation() and APawn::GetPawnViewRotation() is what you should use.
By default, they will give you the location and rotation of the centre of the pawn’s eyes (I believe). You can override this behaviour if your crosshairs work differently.

You can then get the forward vector by using the GetForwardVector node on PawnViewRotation and multiplying by whatever.

Direction = PawnViewLocation + Forward.

For more accurate results, you can pass that information to a LineTrace.

Trace from camera out a few meters. Using the hit result (return, Impact point, trace end) do a select to determine which to use. Get weapon muzzle and Find look at Rotation from it and the return from the select. Make transform (loc:muzzle location, Rot: Find look at rot).

This will work regardless the camera position… FPP, TPP, ADS etc

1 Like