LineTrace Returns OutHitLocation Null When Clearly Hitting Collision-Enabled Objects

I’ve just started making games in UE5, I switched from Unity. I’ve started by trying to modify the FPS Template to get a feel for how the engine works. I tried to switch the weapon from physics projectile shooting to raycasting/linetracing + impulse but the line trace returns null in certain places with very good consistency (which is kind of a bad thing).

The video button is greyed out so I guess I have to describe the code…

It finds the camera location and puts it in as the start location of the linetrace. Then it finds the rotation of the camera and gets the forward vector, multiplies it by a large number, and puts it in as the end of the linetrace. The script then preforms another linetrace that casts from the barrel of the template gun to the hit location of the first linetrace. It draws a visible line from the barrel of the gun to the hit location of the second linetrace. With the red debug line, it sometimes does not show the red square at the assumed hit location and the visible line draws from the barrel to (0,0,0).

You need to take the forward vector, multiply it, and then add it to the start location. Did you do that?

I figured it out! So I’m linetracing to see the location the camera is aiming at, and then tracing to that point. The hit coordinates are not infinitely precises, so if the hit point of the first line trace is rounded to be outside of the hit object, then when we trace to it there will be no hit. The solution is to double the distance of the second linetrace to ensure it hits the object. Very complicated… :slight_smile:

Yeah, I figured it out. It was far too complicated to ask others for help, you really need to know the code for it.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.