1
0
forked from 0ad/0ad

Fix a rare case of unit 'gliding' while moving.

Fixes a1dc9cadd8: if the speed doesn't change, UnitMotion doesn't update
the visual actor. Unfortunately, if another component has in the
meantime reset the animation to 'Idle', the unit will now move while
Idle. This can happen when leaving formation to do something else,
though it'srare.

This fixes that by instead always calling VisualActor, which does its
own checking to avoid redundancy. It's a bit less efficient, but not too
much.
Note that this relies on UnitMotion::UpdateMovementState being called
after any UnitAI code that could reset the animation to IDLE.

Differential Revision: https://code.wildfiregames.com/D3619
This was SVN commit r25011.
This commit is contained in:
wraitii 2021-03-04 18:32:48 +00:00
parent 007bf75264
commit 4b7b9325ac
2 changed files with 3 additions and 1 deletions

View File

@ -1168,7 +1168,7 @@ void CCmpUnitMotion::UpdateMovementState(entity_pos_t speed)
cmpVisual->SelectMovementAnimation(speed > (m_WalkSpeed / 2).Multiply(m_RunMultiplier + fixed::FromInt(1)) ? "run" : "walk", speed);
}
// Speed change, update the visual actor if necessary.
else if (speed != m_CurSpeed && cmpVisual)
else if (cmpVisual)
cmpVisual->SelectMovementAnimation(speed > (m_WalkSpeed / 2).Multiply(m_RunMultiplier + fixed::FromInt(1)) ? "run" : "walk", speed);
m_CurSpeed = speed;

View File

@ -475,6 +475,8 @@ public:
ENSURE(name == "idle" || name == "walk" || name == "run");
if (m_AnimName != "idle" && m_AnimName != "walk" && m_AnimName != "run")
return;
if (m_AnimName == name && speed == m_AnimSpeed)
return;
SelectAnimation(name, false, speed);
}