Line trace hit normal when tracing on edge

Hi,

I’m working on a wall climb system and need to store the normals of walls to align my player character. To do that, I’m tracing a line from the center of the character along his forward vector.

I’ve noticed that there are some problems with the resulting hit normal when the line trace exactly hits an edge of a curved wall. This also leads to jittering and the returned normal direction changes every tick.

In the attached image you can see the start of the trace (the red X) and the returning normal in yellow.
It’s quite logical because an edge can’t have a normal but I’m wondering how to solve this problem and how to get a proper aligned and “stable” normal?

Thanks,
Daniel

Isn’t that just the correct normal for the face the trace is hitting?
The edge itself can’t be hit by a trace yeah, it has no surface, so it either hits one face or the other. I’m not sure how Unreal determines which is hit in that case. But you’ll get the normal of one or the other. So some sort of averaging/smoothing would work.

You could do a moving average of the normals, or an average from multiple traces from very slightly offset locations, with the results averaged. This will be stable even if the character was stationary and happened to be in a position where the trace would be hitting exactly on an edge using the old method. That seems fairly unlikely to happen though. And also technically it could still pop between different values in some cases. So the moving average of normals should work, since the player will always be moving around, and unlikely to be lined up with an edge. Basically it will just smooth out the values a bit, at the cost of a slight lag getting the actual value, the more samples the more lag obviously.

The average function: (make sure Total is a local variable)