Convert my player character's Actor Rotation to Control Rotation

TLDR: I’m trying to figure out a way to convert the yaw format of Get Actor Rotation (+/- 180) to the yaw format of Get Control Rotation (0 to 360). Ideas please? :slight_smile:

Here’s my simple setup for my player Character’s Spring Arm/Camera. When triggered, the camera lerps between a directly behind view (with Roll/Pitch/Yaw), and slightly above and behind view (lifted up by a Spring Arm Target Offset, and only on Yaw).

For the purposes of my game, it works well. In the directly behind, yaw-only mode. So, if the player goes beyond pitch +/-90, the plane flies directly towards the camera and this is what I’m looking for.

So what’s the issue? The thing is, I’m changing my player character from control-driven to physics-driven, so instead of Add Roll/Pitch/Yaw Input and Pawn>Get Control Rotation or Player Controller>Get Control Rotation (which are now zero), I’m using Add Torque.

This is where a quirk of Unreal’s rotators becomes a little awkward. It’s well known that Get Actor Rotation and Get Control Rotation use different value formats, and will give different values when you print them:

Get Control Rotation: Roll (0 to 360), Pitch (0 to 360) and Yaw (0 to 360)
Get Actor Rotation: Roll (+/-180), Pitch (+/-90), and Yaw (+/-180)

Normally, the engine treats these formats identically. It’s not noticable unless they are split. So, now when I split Get Actor Rotation for the above and behind view, there is an awkward new yaw flipping.

So to conclude this vast narrative, I’m trying to figure out a way to convert the yaw format of Get Actor Rotation to the yaw format of Get Control Rotation. Ideas please? :slight_smile:

Hey there @DavidOConnor! If all you need is a bit of logic to get control rotation from actor rotation, here’s some logic that can pull that off! (note: only works for Yaw.)

You can also reverse this to do the opposite.

1 Like

Nice one! Converting the actor rotation to the control rotation(equivalent) in yaw is exactly what I’m after.

Your solution looks like the kind of thing I’m looking for (unless there is a native function). Regrettably though, it doesn’t seem to have any effect. Maybe I’m not applying it right?

If there is a more elegant way to do this, feel free to chime in :slight_smile:

Thank you @SupportiveEntity! My pawn flies upsidedown sometimes, so I had to make adjustments for this. It’s hacky (apologies), but here’s what I came up with:

I’d only tested the output with prints when I wrote that quick one up before so it could have unforeseen consequences, but it looks like you solved it there. I don’t foresee any direct consequences from your setup. Shifting things to quaternions is always a pain. There’s likely a simpler method to pull it off but it seems sound for now!

1 Like

Again, sincere thank you @SupportiveEntity. The time you put into helping people out is flipping wonderful.

After some thought, I switched it to a Curve Float, and adjusted it for Roll because I have a 6dof character.

Apologies that it’s a bit hacky though, and may not suit everyone’s purpose:

image

Here’s the Curve Float, I made the curves linear:

No problem! The way I see it, hacks are generally fine as long as you aren’t going to need to touch the code again, it’s not a performance liability, and not going in your portfolio for best independent developer of the year. If this is just for filtering your input, then unless you’re creating bindable controls, you may not have to worry about it. Every game is different though! There’s definitely cleaner ways to pull it off though, so maybe during refactors you could take another swing at it!

If your answer is satisfactory you could mark yours as a solution, or leave it open to see if anyone else has the math chops to answer it cleaner!

Absolutely, maybe someone has the time/skills to elegantly solve this once and for all.