Transform won't rotate through full 360 degrees - Ping Pongs between 270-90


I have a character which can walk along a wall as well as the ground with no problems. While I don’t have any problems with the character’s rotation itself, I am having trouble with the numerical values of its rotation when it is on the wall.

When I rotate my character everything looks fine in the game, it can make a full circle. However when I look in the inspector at the transform’s rotation, it “ping-pongs” between 270 and 90. if I rotate in one direction continuously, the inspector value will go up to 90, but then as I keep rotating, starts going backwards back down to 0 and then down further towards 270.

Why is this happening and how can I fix it? I need to have the correct rotation value because it is used by something else in my game.

It doesn’t happen when the character is on the ground, only when they are on the wall.

when on the ground it rotates through the y axis, and when on the wall it rotates through the x axis. The same thing happens whether I am rotating the character in gameplay, or using the gizmo in the scene view.

Any help much appreciated! :slight_smile:

I don’t fully have my head wrapped around the math, but I think the issue is that multiple numeric representations are possible for the same facing. (ie the two values that the inspector is ping-ponging between are equivalent)

Perhaps you’d have better luck if you introduced an extra level in your hierarchy. In the outer level you could rotate to align with the surface you’re walking on (the wall) and in the inner level you could rotate to face the direction you wish to go along that surface. Since the inner value should only involve a single non-zero Euler angle, I suspect it’ll be more predictable for what you need.