I’ve seen this topic discussed a few times before, but no one really seems to provide a solid answer to it.
Here’s my own take and problem: I’ve got three control states - (-1, 0, 1). -1 is backwards, 0 is idle, and 1 is forward.
Initially, I just used a direct button press. Down = 1, up equaled -1, and states between caused idle to occur. That required somewhat of a complex animation tree, with ineffectual smoothing between animation states.
Now, I have started using Blend trees - however, direct switching between the three states causes abrupt animation changes. I’d like to smooth that out, but I’m not sure of the best way to do so.
This is what I have come up with so far:
private void PlayerControlSystem()
{
if (ControlKeysPressed)
{
ControlSwitch = Mathf.Lerp(ControlSwitch, 1, 0.1f * Time.deltaTime);
}
else
{
ControlSwitch = Mathf.Lerp(ControlSwitch, -1, 0.1f * Time.deltaTime);
}
}
It partially works, but has some problems such as when it hits zero it should idle, but keeps trying to walk/run as the value itself is actually 0.4456457f (to infinity). I’d like to create a quick and smooth tween between animations instead and it properly stops when the controls are at correct values.
How can I accomplish this?