Why is my line trace flickering? seems to be colliding or z-fighting with the mouse cursor

I have this line trace set up:

However, when I’m not aiming at the floor but at anything else, it starts flickering. if I print a string for a tick along with the trace, displaying the name of the actor hit, the string will also flicker.

(in this video, start location was at the muzzle of the weapon, I changed it to camera manager to make it simpler and easier to debug, but the outcome is exactly the same)

any ideas what’s going on?

Seems pretty wild, have you tried using the Impact Point as your end location instead of just Location? If that doesn’t work the only other thing I’d think of is a collision issue

I have, same deal.

You can replicate this yourself quite easy if you want, just create a top down template project and add this code to the player controller bp:

you just need to put the cursor over the blue boxes.

it works with the third person template all the same if you make a new player controller and put that code for line trace.

It seems to be related to the mesh, and their collision meshes.

If I make a simple cube and export without changing anything, it works. If I delete the auto generated simplified collision and add a simple box collision, line trace will start flickering when hovering it.

now, If I get a cube that’s already not working, like the blue ones from the template, remove the simple collision, and add a 26DOP simplified collision to it, it stops flickering.

I have no idea how to fix it for skeletal meshes like characters, which is exactly what I need though since this line trace is for shooting enemies and causing damage without using projectiles.

any ideas how could i fix this issue?

Does this happen when you untick Trace Complex? You’ll need a simple collider then. Complex Tracing ignores it anyway.

Yeah, I have been testing with it unticked. if I tick it back, then it flickers with about every single mesh in the map.

It seems that the “get hit result under cursor by channel” node is bugged with some kinds of collisions.

If i use “convert mouse location to world space” it works just fine, even though I have no idea what’s the logic behind this math to convert a world location to turn into an actual world space location. either way, found this online, replicated, and it worked with all meshes:

Can you explain why the trace starts at the muzzle but you’re using Player Camera as a start?

Yeah I explained in the first post

(in this video, start location was at the muzzle of the weapon, I changed it to camera manager to make it simpler and easier to debug, but the outcome is exactly the same)

1 Like

Does it behave like this will all meshes or just this wall? Can you test it with a simple engine box? Busted mesh normals?

it happens with all meshes. i thought it wasn’t happening with the ground mesh, but that’s because collisions for it are off, and the line trace is actually interacting with the under side of the ground which is a separate mesh, and it is tracing the back face of it. probably has default collisions

With Trace Complex enabled, I cannot see this issue on my end. My assumption is that this is an asset(s) issue.

Not sure what I’d need to do to make it not work.


it happens with all meshes.

With default engine meshes? Or custom imported meshes?


To unsolve:

image


image

This means you’re not tracing far enough to reach the wall; and I’m almost 100% this is not the script used for this:

This is very weird. I created a brand new top down template project from scratch and just added that code to the player controller, and it happens.

either way, using the “convert mouse location to world space” node method, it works without issues so I guess it’s fixed

fair. here it is, this is the code:

and this is the outcome:

1 Like

Where did you find it:

What if this is 0 :exploding_head: You’re going to unmake the engine. ;p

I guess UE can divide by 0 lol

found it here:

actually, that math isn’t returning the proper mouse location. as I move the cursor above my character’s eyeline, its line trace stops going up.

any ideas how to get cursor location properly from that node?

I don’t know what it’s supposed to do :person_shrugging: Looks like a random attempt to do what exactly?

visible headscratches Not sure what’s the use-case scenario here. There may be some.

If you want to trace cursor depth from the camera:

1 Like

this is what I’m trying to do, to get a line from the muzzle of my weapon to the location of my mouse cursor, and get a hit.

however, if I do it this way, it follows the mouse but always stops short of hitting anything:

Like so then:


If you want to trace against a horizontal plane only, ignoring Z, and catch hits between the player and the projected cursor:

1 Like

Thanks! This worked perfectly, it’s exactly what I wanted.

I guess my initial issue was that I was ending the line trace at the cursor world location, and not multiplying it by anything so it would extend beyond that point, so every other frame it would just randomly end just short of hitting the object under the cursor.

The limiting to a horizontal plane should also work for what I’m thinking, but is there a way to limit it to an angle, instead of a plane? like a vertical 2d cone instead of a plane

And the only other thing I can think of asking is how would you add a bit of random variation to the hit point? I figure I’d add some random floats in range for the X and Y values of the end location, but I don’t really see where, and this didn’t work:

1 Like