How can I fix the linetrace to shoot at the location pointed by the CrossHair


The link to the CrossHair bp:DynamicCrossHair.uasset - Google Drive

Can you show your linetrace code?

Right. The problem is your crosshair is firmly screen center. Which means a normal camera trace is needed.

If you want to trace from the gun, I think you have to do the whole thing from gun, and move your crosshair around dynamically.

1 Like

Normally GetActorEyesViewpoint gets you the camera position and direction. It might not be exactly right in third person so I’d double check, but usually it uses the camera components as a source if they exist. If not, use the camera component’s position and direction instead of GetActorEyesViewpoint.

And you can use that as the source of the linetrace.

It does look like you’re using a camera vector of some sort, not sure if that’s a reference to the actual camera you’re looking through. It should work though normally.

That would give the position the crosshair is aiming at, and then you can make your gun fire a bullet from where the barrel is to where the crosshair is.

It may not be 100% accurate since that’s not literally where the gun is facing but it’ll feel right to the player.

In fact most games do something like this, and no one notices, especially if it’s a hitscan trace.

Check the “DeprojectScreenToWorld” node from the GameplayStatics library

This is correct, as you’d otherwise require complex IK solutions for the gun’s barrel rotation. *Edit not that this is bad but it is usually unneccesary. I like to do this when simulating realistic recoil or animation based weapon actions. In many non realistic games you won’t need this.