Getting a sidescroller character to turnaround in a more natural manner?

Recently, I’ve been trying to fix an issue with the default sidescrolling platformer blueprint that I would greatly appreciate some help with. The problem is that when the player taps the left or right button on the controller the character doesn’t automatically make a 180-degree turn to face the opposite different and instead can end up facing towards the screenshot which is something I do not want.

To remedy problem I tried using blueprint I found here


The problem though with setup is that when the character turns around, they do so instantaneously, which I am not personally too keen about, as I find it to be rather janky-looking. I would much rather have the character quickly rotate around in a more natural manner instead of instantaneously turning around.

The same forum topic also contained recommendation which purports to give a more natural-looking turnaround but I wouldn’t know because I’ve been having problems implementing particular blueprint.

Specifically, I can’t seem to find the component labelled ROT with the clock symbol next to the name.

Would blueprint work for what I’m trying to achieve? If not, then does anyone have any other suggestions on how I can get a more natural turnaround for my sidescroller character?

While I must admit I haven’t looked into the sidescroller at all, is kind of a basic 2d situation.

maybe explaining how that normally works in 2d you can whack your way to a solution.

If Face x > and input <
transition to left with animation
go idle.

if face x < and input >
Transition to right with animation
go idle

Since unreal is a 3d space, you can rotate the idle via code with an Finterpto based on the same principle without the need for multiple idle states or animation states.

How I’d do that.
First pull out current character movent forward direction and break rot.
Take yaw and type finterpto to get the interpolation.
Get 2 make rot and set the target to match the 90/-90
plug in to the 2 interps, and add 2 different actor rotations per interp.

Handling that with anims, I would create an all encompassing 4 point animation with rotated idle poses.

Left, left forward, front, right forward, right

And once you feed the finterpto result into the anim blendspace you should get a near perfect interpolation that you adjust in 2 spots.
the anim it self (defaults at .2 I believe)
and the finterp that governs the overall speed of the turn.

… if you cant get it I’ll take a crack at it and share results :wink:

Yeah, I’m not having much success with :(. I can’t get the Break Rotator component, I’ve tried getting it from dragging off the InputAxis MoveRight component but it doesn’t appear in the list. I assumed that when you said Current Character Movement Forward Direction you meant the InputAxis MoveRight component, as there isn’t a component by that name in the character movement blueprint.

If you created the character blueprint as a character you have it in there.

I’ll share a link shortly, in the mean time if you need to find break rot you can disable the context sensitive check box.
if you start typing movement the movement component should also come up.

I think both first person and third person have in the default character blueprint movement section.

granted maybe sidescrsidescroller template is different, you can totally ditch the template character blueprint and craft your own.

After looking at it I would totally suggest a re-write. However, in an imperfect world, I’ll offer an imperfect solution tomorrow.

What you have is a good start, I ended up with a similar logic from scratch.
The reason i’m not sharing it yet, is that I have to test the animation timings and notifies involved.

The idea is that you add a little portion before the check for left/right to halt that check from happening at all if the value is 0 - no axis movement.
From that, you set a bool value for “turning”.
The animations should be the ones to turn the “turning value” off.
The result will likely be that you end up turning at the pace of the animation in the anim state but since can also be done with a montage I have to consider the 2 approaches and maybe just implement 3d movement.

For whatever it’s worth and because it took me a bit to realize. the reason you are stuck on the same axis and it looks/operates so wierd is the movement controller y=-1 multiplied by the axis.

It’s just an overall bad way to lock in planar movement… could be done much nicer and also make it easier to go forward/back…

Alright, I got something that’ll do it in terms of character blueprint. It looks (visually) virtually the same as the starting of the template, but it’s not.

The character actually turns via set actor rotation Wholly. You won’t get stuck in 3/4 spots not even when using a controller because of the Integer rounding.

Because of the “set actor rotation” you will be able to manage the animation however you want, but the “axis” of the actual rotation is locked in no matter what in such a way that the character will always end up at 90 or -90.

The default value of the Direction and New Direction variables are kind of important. they need to match your character’s starting orientation should you ever change it.
(
create a “begin play” event
read actor rotation, override it to
lock it in to 90 -90 by way of
“Map Range Clamped” > in a -90, in b 0, out a -90, out b -90 IF range is < 0 - reverse for the other side.
Assign the direction “default” value accordingly.
Any time you add the charter or rotate it on screen it will look to the correct world orientation.
)

Here’s the screenshot of the movement syntax.


Next up I’ll work my anim state and come back to update :wink:

That went quick. I did update the image above to . I’ll leave that file just for reference, but use one instead.


Here are the various parts starting with Anim BP to get the switch running

Then you have the Default Animgrah, the content of the Idle+Switch with a new statemachine

Then you have the actual contents of the new idle state machine. NOTE: the switch animation HAS to have loop disabled for the transition to toggle back.


is the rule to go back - going to is obviously just the Boolean Side Transition
NOTE: “ThridPersonRun” will be different for everyone, time remaining will pop up as the second option when you right click and type “ratio”. IF the transition fails, your animation is set to Loop…

Very interesting, thanks for share it, I was looking for something like for a while without any results but now I have a direction. Also, could you please share a screenshot of the “begin play” piece of the blueprint, I coundn’t understande very well that part. Thanks!

I don’t think I have it anymore.
Drag off a float and type map range clamped.
the values should be as above “in a -90, in b 0, out a -90, out b -90 IF range is < 0 - reverse for the other side”
by re reading it there is probably a wrong value here.
if A is between 0 and -90, B should probably be between 0 and 90.
I other words a 180 degree value.

The goal is to determine what ditection you are facing and set the initial value of the Direction variable to it so that the character knows which way he’s facing.

To do , you force the value with the map range claimed because potentially the character is facing you when placed rather than facing the correct direction.

Also, was made as I was just learning the engine, so doing it today would probably be very different.

For one i started referencing and changing the animation information directly from the character, eliminating all but one cast to node within the character BP.

Second, fixing the axis to an integer was specifically for what I was developing. I did not want the axis to have a speed variance on joypads vs keyboards. Being a fighter game style thing that was important to me.

The last thing is the use of too many variables.
They take up some memory and there is really no need to keep them in memory when the information is already avaliable off the characters rotation that is already in memory.
Get the rotation, use a map range clamped for ease of use. You want a result between -1 and 1.
Then you check if >= 0 to and split the code based on the branch result. Its really the same thing all in all, just slightly more efficient…

Hope that makes sense.