Rotate character 180 degrees while playing animation

I’m looking for an answer in C++ if possible.

I have a character with enhanced input and animations. It’s a 3D character constrained to move in a 2D plane. The character has an attached camera with a world rotation which views the scene from the side.

The user can only control if the character moves left or right using the A and D keys:

AddMovementInput(Direction, Value);

How can I turn the character to face the travelling direction?

I want the 180 degree turn to play out over a set duration. Even if the user just taps the direction key briefly, the character should still smoothly rotate to the target direction. Ideally this would also trigger a custom turning animation. The camera should never rotate.

I have tried a lot of things but nothing works as intended.

You can use a timeline to rotate the mesh :blush:

Here’s a tutorial on timelines in C++:

Make sure that the animation is in place and the animation doesn’t actually turn, since we’re already rotating the mesh. It should just be some in place leg movements with a head turn or whatever you like.

Also, this can as well be done by purely visuals so that we don’t need to rotate the mesh ourselves using a timeline. Something to consider. You can just negate a vector type variable that stores a unit vector inside every time the character “turns”, if you wanna use the forward vector.

Hope this helps!

1 Like

Thank you @VisAgilis !

Do you mind elaborating on “doing it by visuals” and how that would work? Is that cheaper or easier?

I meant only playing a turning animation and not getting into code.

Having this inside the animation blueprint would be the most suitable way, as this will be a part of the common continuous mechanics of the character.

I didn’t get what you meant by cheaper but absolutely it would be easier :star_struck:

1 Like