First person shooter template not aiming straight

I’m currently following a tutorial for making a little shooting gallery, and I felt like adding some stuff for practice. I’m just using the first person shooter template for this one, and I made some modifications to the projectile so it moves faster, disappears on impact, triggers a particle effect, and is not affected by gravity, as in moving straight forward. However, I noticed that the projectile doesn’t really hit where the cross-hair points in the middle of the screen. I’m guessing the projectile doesn’t actually have a trajectory based on what I’m aiming at.

Is there an easy way to fix the trajectory so that the projectile hits what I’m aiming at?

If I remember it right, the crosshair in the FPS template is not in the middle of the screen by default. They did it because it better reflected the trajectory of the ball launched by the default gun in the Character BP, but you have to either create your own hud/widget with a crosshair, or go to the default one and change its location.

Maybe, but as far as I can tell, it doesn’t consider the distance from the player, so the accuracy will be different depending on how far away the target is. I think I would be happy to just do a line trace from the tip of the gun (which is already set up in the template) to what is in the crosshair. I believe I can set that up, but I have no idea how to get the projectile to start moving along said line trace.

Find Look At Rotation from the gun tip to the trace Hit Location, Get Forward Vector from the resulting Rotator, and use it to set the projectile velocity.

Or use the Rotator as projectile direction, I don’t really remember how it’s set up in the Projectie Movement component.

Edit: you don’t probably want the trace from the gun; it won’t be accurate. Trace from the camera will be better, but again, depends on what you want to do.

There’s a couple ways to fix this, when I started this issue took me days to figure out lol. But the most accurate way of doing this:

Do two line traces, one from the camera forward until it impacts something, then one from the gun, to the impact point of the first trace. This is the most accurate way to have a projectile shoot (from the gun) to where your reticle is currently aiming.

You’ll still have the issue of the template cross hairs not being perfectly centered on the screen but that’s an easy fix.

Alright, I’ve been trying this solution now, and it’s getting there. However, for some reason sometimes the projectile goes entirely in the wrong direction, seemingly completely random. I can be aiming at the exact same spot, and every 5th projectile or something will go somewhere else. Also, the line trace sometimes just detects a hit in mid-air where there’s nothing the way I’ve set it up now.

Here’s the BP so far:

Also, while the projectile is now going the right way when it works, I’ve noticed that the line trace hits above and to the left of the (corrected) crosshair. The lower right corner of this debug box is where I’m aiming, and the line trace goes to the middle of the box. Is that possible to correct?

That can be caused by a few things. First I’d check the basics:

1.) Make sure that the trace from the gun is coming from the end of the barrel and not inside the barrel (sometimes the trace can collide with the barrel itself).

2.) Drag off any of the “hit” options from the hit result of the gun trace and print a string of what it’s hitting. So you can see what the trace is hitting whenever it’s fired, it will help you troubleshoot.

3.) As far as where the trace is hitting, make sure that in your widget your crosshair is centered. It most likely is not. If you’re tracing from your camera forward, the trace itself is hitting center screen. The crosshairs are most likely not centered.

I’ll take a look at the BP when I get home tonight.

After toggling around a bit, I found out that the fact that I grabbed “blocking hit” from the first line trace and not “initial overlap” was causing it to fire in weird directions. So “initial overlap” is the correct answer from what I can tell. The line trace still goes in weird directions when it hits nothing, because I set up some sort of failsafe so that the projectile would just go straight forward if the line trace didn’t hit anything, but it doesn’t affect the direction of the projectile in that case.

The thing about the projectile hitting something in mid-air was that the line trace was either hitting a doorway collider that didn’t ignore line traces, or a previously fired projectile that also didn’t ignore line traces.

Also, that thing about the line trace hitting in the corner of the hit box was right - that box is 16x16 pixels, so you have to offset the crosshair by minus 8 pixels in both axes.

I’m leaving the corrected blueprint here, in case someone might find it useful:

I toggled around a bit, and I believe I found the solution: I had the first line trace set to “blocking hit”, which made the projectile move in weird directions (towards one specific point because it didn’t hit anything, it seems, even though it is hitting something as far as I can tell). I set it to initial overlap, and then everything seemed to be working. I also had a failsafe which would send the projectile straight forward if the line trace doesn’t hit anything, and in those cases the line trace points towards that one point it did with blocking hit, but the projectile still moves correctly, so I don’t think it matters.

About the crosshair, you people were right. This box that appears at the end of a line trace is 16x16 pixels big, and offsetting the crosshair to -8 pixels in both axes seemed to do the trick. It doesn’t really make a whole lot of sense to be that the line trace would now be accurate at all distances by moving the crosshair, but it does seem to work.

Here’s my final blueprint for it, if anyone might be interested: