Actor rotation being changed from -180 to 180?

When using a timeline to interpolate an actor’s rotation, if I rotate it from anything to -180, once it reaches -180, it changes its rotation to 180. 180 and -180 are the same direction, but their being different values messes up the math I’m using to calculate other things based on the actor’s rotation.

Here is a copy of the script causing the problem. When the NewCameraYaw is -180.0, the actor’s rotation is set to 180 at the end of the timeline.

Does anyone know how to stop Unreal from changing my actor’s rotation values?

Thanks in advance!

1 Like

This might help

I’m creating a camera movement system where the player can press A or D and they will rotate 90 degrees right or left. So if I try to clamp the values to always been between 0 and 360, it will change the direction the player rotates.

A simple solution would be to limit the rotation to -179.9 to 180…

Mentioned above, this wouldn’t work, as the interpolation needs to be able to rotate indefinitely in either direction.

can you show us your blueprint? It may help shed some light on it…

Sure thing. I just updated my original post with a link.

1 Like

You could do it something like this:

2 Likes

3 Likes

This is a good solution and I like it a lot, but since the new rotation is based on the rotation of the actor when the function is called, it breaks if the player calls the function again before the timeline ends, as the new starting yaw will not be a multiple of 90 anymore. I could add a “IsMoving” variable to prevent the player from inputting another rotation before the timeline ends, but I’d prefer to let the player move more freely.

2 Likes

Wow, that worked perfectly! I replaced the top-most GetActorLocation call with another MakeRotator using OldCameraYaw, so that the original rotation doesn’t change as the timeline runs.

On paper, I don’t think anything should have changed, because this is basically the same code. But I guess the rotator interpolation calculation is slightly different, which fixed this bug. Thank you!

1 Like

I think the rotator interpolation uses quaternions in its internal calculations so it doesn’t flip abruptly.

2 Likes