Why is my projectile not shooting straight near my character?

Edit:

Check last comment for Blueprint with answer


Original Answer:

From the comments in the thread and your blueprint, it looks like you are doing this:

Getting the spawn location for the projectile by adding the GunOffset to the current position of the Pawn. You are then assigning the rotation of the projectile equal to the rotation of the Controller, basically your Camera. Then, you spawn in the projectile and give it some velocity in the direction it is facing.

Depending on your GunOffset, you will get different results because you are not compensating for the difference in position with respect to your Camera and your projectile spawn position.

In order to achieve what you are looking for you have to compensate the projectile rotation to account for the difference in position from your projectile spawn point and the camera position. What I’ve seen people do is use a Line Trace from the Camera position to get one of two things:

  1. Get the position of a collision within a certain range (weapon range) and use that position to correct the projectiles initial velocity vector. (LineTraceHitPosition - ProjectileSpawnPosition).Normalized * ProjectileInitialSpeed will give you an initial velocity vector for the projectile to have it “Shoot” toward the point where your Line Trace hit.

  2. Get the position of some default max distance for the weapon in the direction of the camera look vector (your crosshair) and use the same logic as number 1 to get that point and correct the projectile initial velocity vector.

Hopefully this helps you get going with it! =)

1 Like