a* version: 5.2.3
unity version: 22.3.21f1
graph: recast graph
ai: followerEntity
There is a rotation issue with followerEntity
. For example, when the unit goes into an attack, followerEntity.isStopped
is set to true
.
During the attack animation, the unit is made to look at the target using transform.LookAt(target.position)
.
However, when the attack is finished, and followerEntity.isStopped
is restored to false
, the unit’s rotation returns to the position it was in when isStopped
was first set to true
.
This is a Video to help with your understanding.
Example video
This is my code in Animator State Behavior.
public class ZombieSMBAttack : SceneLinkedSMB<Zombie>
{
// Attack State Enter
public override void OnSLStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
m_unit.IsAttacking = true;
m_unit.ai.isStopped = true;
}
// Attack State Update
public override void OnSLTransitionToStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
LookTarget();
}
// Attack State Update
public override void OnSLStateNoTransitionUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
LookTarget();
}
// Attack State Exit
public override void OnSLStatePreExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
m_unit.IsAttacking = false;
m_unit.ai.isStopped = false;
}
void LookTarget()
{
if (m_unit.Target != null && m_unit.Target.IsAlive)
{
m_unit.transform.LookAt(m_unit.Target.transform);
}
}
}