Line trace go through wall angles

I have shoot system with line trace, but for some reason because the linetrace starts from my camera if i go into a wall angle and shoot the bullet goes through the wall. I tried making the line trace come directly from the muzzle of the gun and go out towards the crosshair, but then the shots are not at all accurate with where the crosshair is pointing.

The problem:

My BP:

Hey @GeorgeTheDev_1!

So to change subjects for a second to get a good grasp of your system, what does your projectile system look like? Is it just hitscan? Meaning there’s no actual bullet? Or is there a physical projectile?

1 Like

Is just a hitscan, not a projectile

Okay. So.
What you want to do is draw another line trace… But the END of that line trace will be the “Out Hit Location” of the one you’re already using!

So keep the one you already have. THEN draw another line trace using visibility from, say, the gun. Your aiming reticle offset from the gun then won’t matter.

You’ll use that second line trace, then compare the “out hit hit actor” from both (use “IsValid?” on each out hit actor first, then compare the two with an =). If they are indeed the same use a branch to confirm true, and do your hitscan hit! (No hit on false because the gun can’t see the target)

This way your targeting will be based on camera, and it will only work if the gun can draw a straight line to the target :slight_smile:

1 Like

Is that correct??

For some reason sometimes the is valid fails for some objects, but the bullet is always going through walls in angles

the result:

This should work.

Camera trace provides us with an END location for the firing trace which we pad a bit just incase we nip something that won’t be there in the next trace. Margin of error kind of thing.


EDIT: Forgot to Math

1 Like

When i do the multiply it breaks the end location

Bp code:

Sorry about that. I forgot to do actual math. Updated the original.

:sweat_smile:

Being a stickler for performance and simplicity I couldn’t let it go.

Here’s a one and done trace for hitscan. Tested it a bit seems to work correctly.

2 Likes

Here is the result :frowning:

If i apply the math fix you edit, for some reason i see only some red dots when i shoot
image

Your multiplier is in the wrong position. Needs to be After the Get Unit Direction node.

Select Vector → Get Unit Direction → Multiply → Add

1 Like

If i get close to the angle it does the same thing
image

BUT if i go a litle bit back and try to do this it blocks the bullet

Your muzzle is clipping through geometry. Collision hulls do not block from the inside. Exterior only.

Traces are doing their jobs correctly. Quick solution is to add a collision component to the muzzle area.

World Dynamic, Overlap all except camera/visibility.

Begin overlap: isblocked(true)
End overlap: isblocked(false)

Branch (isblocked)[false] → do trace

2 Likes

The broblem is not fix yet… :frowning:
the collision sphere blocks the trace even with these settings

Instead of using a sphere you could add a line trace from the hit location back to the muzzle location (set the hit actor and the gun as actors to ignore for this trace). If the hit location to muzzle trace produces no hit then you know there’s nothing between muzzle location and the original hit location.

Use capsule or box, scale it and pull it back just 2cm from the muzzle socket. This collision should be scaled pretty small to begin with.

OR

Project settings → Collision : crate a custom collision channel. Call it NoClip (default: Overlap).

Have your trace ignore the channel.

1 Like

I tried it, does the same thing
(I tried moving the sphere but nothing…)


The new trace channel

Go check the collision for the walls etc. They have to have Overlap on the noclip channel.

1 Like

I tried it but again…nothing…

The result:
image

Your NoCLIP needs to be an OBJ Response, not a TRACE Response.