[BUG/IMPROVEMENT] Align to Ground caught in confused rotation loop when idle


I confess when i read the manual I deliberately looked for this bug, sorry!

1. Character controller variant (Ultimate Character Controller, First Person Controller, etc).

2. Unity version (include which SRP, beta Unity versions aren't supported)
2019.3, URP

3. Bug description

The manual states (for Align To Ground): "Depth Offset allows for multiple raycasts to be used which allows the result to be averaged. " This is very common, but is often flawed in game.
Imagine a ramp that goes up and then down the other side. As you go up side A, both rays hit side A and the normal is A's normal.
As the first ray goes over the crest of the hill, the normal becomes the average of A and B, and the character begins to rotate forward.
However, if the first ray only just goes over the crest of the hill, the act of rotating, brings is back to side A and the normal becomes A again, character reverses its rotation until the first ray is now over the hill again ..... repeat loop until player moves.

It is not a game breaker, because you can move, but it is ugly and if you are trying to edge up a hill to snipe, for example, this would be maddening.

Possible improvement, but haven't tested in UCC environment: instead of averaging the normals, take the two hit points, find the mid-point of the two hit points and come back orthogonally from that on the plane defined by the transforms right (if that doesn't make sense i can explain better). in this setting, the passing of the first ray over the hill has little impact on the mid-point of the two ray hits and causes very little rotation. Could still be buggy in certain situation and you will need a fall back if one ray misses, but i imagine you have that already.

4. Steps to reproduce
put a large cube in demo scene and rotate it 45degrees to make two ramps.
Set Align To Ground on Nolan with depth offset of 1, and remember to set slope limit to > 45 degrees.
edge up the hill and observe - see video:

5. The full error message (if any)


Staff member
The depth offset is meant to be used by four legged characters so if for example you are just starting to go on a slope the long character will start to realign correctly. By finding the mid-point it wouldn't find this realignment correctly. In this case I think that the solution is to decrease the distance so if you are at the peak of the two cubes the raycast that is in the air won't hit anything.


Sure, I did this to just highlight the issue, I wanted to use the depth offset on my prone/crawling humanoid, for the same reason as non-humanoids and it creates this issue.
If you use the midpoint you'll create a gradual transition, almost circular around the corner