Character rotation leaning help!

Hej!

I’m trying to get leaning working for my character. The result I’m looking to get is my character leaning in the rotation direction.

The paths I’ve been considering is procedurally rotating joints on the spine joints (and possibly even the Root) or having additive animations lean the character. I’m trying to get a good signal for rotation velocity to drive either of these setups but I’m not really succeeding.

Could someone help point me in a direction of a leaning set up somewhere on the interwebs? Or just try and explain it here? :slight_smile:

I’ve gotten pretty far with the procedural leaning, following a youtube tutorial, but the signal I’m driving the leaning with seems a bit unstable.

The additive solution is appealing to me but as I’m fairly new to this engine I don’t know how that would be pulled off - or what I’m imagining is even possible. What I’m trying to do is to have a 1D blendspace with a null additive pose in the middle, and to the left and right of the spectrum there’s an additive lean left and right pose. The idea is that this would be driven, again, by the character’s rotation velocity.

Thanks a lot for any input! I’m of course open to any other suggestion of how to make leaning. I understand that I could possibly make a 2D blendspace with actual leaning versions of the locomotion assets… but then I have to make so many animations and my ambition is to try and keep it slimmer. :slight_smile:

Oh and if you think I’m stupid for trying to get rotation velocity and that I could use something else, then that’s welcome feedback as well :slight_smile:

Cheers

So, assuming this is leaning while running and unrelated to slope matching.

if you want to cheat it.
set up a good leg IK with a decent solver so your feet adjust anyway as you run.
then you can tilt the root bone to get the overall skeleton to lean a bit. It might look a little odd at times if the leg IK happens to hit a step or a high gap on the side against which you lean, but for a 5m setup you can’t really complain.

The proper or more convoluted way would be to implement actual leaning animations with a 1d or 2d blend space (if you need speed to be variable).
you need to separate left and right in their own states to avoid twitching between 180 and 0 as usual with anything that rotates.

so you have the 2d blendspace with base speed at the bottom. Row and the different levels of leans from approx 0 to 15 deg.
and the high speeds with the same leans at the top.

Then you can make your state machine choose which animation to lean into and increase the lean as a product (multiple) of speed and directional rotation clamped to a max of 15 deg.

For the math you will need to fiddle a bit,
a forward vector and controller axis value mashup can help, but you would only get max lean on keyboard, so factor in speed is a good way to render the same result across all of it.

Speeds usually range from 0 400 but do you care? not really.
get the max speed from capsule and find the node to scale the value properly in a range from 0 to 1.
you could even just divide by 400 or times by .004 in a pinch. It won’t be perfect but you just need an idea because the math needs to be based on the max output.

So speed 1, plus rotation input 1 (also the max) = 15deg lean.
Speed .5, input rot .5 = 7.5deg lean
speed 0 input rot 0 = 0.

so in a pinch something like ( max lean / 2 ) x speed + ( max lean / 2 ) x rot might do the trick…

Thank you very much for your answer! :slight_smile:

It’s probably gonna take me some tinkering before I understand all you suggest, but it’s very much appreciated.

You said I’m gonna have to divide the leaning in two separate states. I’m not sure I understand why that’s necessary. Can’t I just have a float going from say -180 to 180 that drives the leaning where the zero lean pose is at 0? I’ve been trying and failing to get a float that does that reliably, so maybe what you’re saying has something to do with that?

​​Thanks!

I’m saving you 3 days of work to just go back to splitting it up.
Working with any angle you get flickering when the values loop from -180 back to 0. Hence it’s often best to split things up to avoid that problem altogether.

This is particularly true with blend spaces - and why you often see people having issues with flickering in walking backwards states.

It’s much better to handle the drastic angle changes “manually” so to speak, then it is to rely on the engine or a normalized angle which can cause said loops - at least for instances where 0 is vastly different from 180 and actually closer to -180…

This is super interesting! Thanks for the advice!

Will keep this in mind when creating the states. I’ll start by trying to get those driver values, though! :slight_smile:

When next I get a moment to boot the engine I’m gonna see if I can manage to get any usable values from this. Do you mean a mashup of the two controller axis values or do you mean a mashup of the controller axis values with the capsules fwd vector? Would I get a vector or rotation from somehow combining the two controller axis that I then compare/diff against capsule fwd vector or rotation?

Sorry, I’m quite new to Unreal. Maybe some of these things would make more sense to me if I’d had the time to try out some things instead of just asking you. I just haven’t had a chance just yet :slight_smile:

No worries, not the easiest thing to start off with.
Driving the value needs to be up to you with testing - as I don’t completely know what you need I can sort of approximate but that’s about it.

In project settings set up the controls properly for movement.
AWSD / Joistick Axis.

You want something similar to this mess so you can block off inputs later on when needed. Might as well set it up/customize it now.


After that’s set, The character can move properly and is able to transmit a few boolean states to check to the AnimBP you can start working the animation side of things.
You want something like this to start (Which should be similar to the default)

Given you have the speed, and the direction, you can already mesh up some calculations off these 2.

You can drop a Print String with duration of 0 to get a constant short read at the top - I would suggest using Append to print to this string and get a reading of the initial values / speed / direction in order to decide what math to use.
You can keep appending new strings onto the Append until you find a solution that returns numbers for what you think should work angle wise with the leaning.
It’s always going (or should be) a factor of Speed and Direction anyway, so this is basically all you need.

Oh and I forgot, you can probably use this node/settings to affect the root bone angle.


Again, it’s not the same as a proper animation, but in a pinch it can give you an idea of how good/bad the lean is.


I ended up implementing something simple myself. not that it’s any good mind you, but in a pinch it gets the character to lean while moving forward.

You sure are a well of information. Thank you! :slight_smile:

If someone ever see this, this is so wrong, cast to character on update animation is crazy, mean you cast on every tick is wrong in every way.