Fluent Retarget (AI) 🐾
7
4
💡
3Quick change to make the AI retarget more fluently, not ignoring your followers, for example!
Explanation: Basically, it just adds the possibility of changing target whenever provoked instead of ignoring any new targets if it’s already chasing somebody.
It just needs a single change in AiController.cs: Add Properties:
[SerializeField] public float m_retargetMinDistance = 2.0f;
Add Method:
private bool CanRetarget(CharacterBase source)
{
float distanceToInitial = Vector2.Distance(transform.position, source.transform.position);
float distanceToNew = Vector2.Distance(transform.position, m_target.transform.position);
return
// distance minor then
distanceToInitial < distanceToNew && distanceToNew >= m_retargetMinDistance && m_retargetCooldownTimer <= 0;
}
Change Method: (OnProvoked)
private void OnProvoked(CharacterBase source)
{
//if (source && !m_target && m_retargetCooldownTimer == 0.0f && CombatSolver.IsJudiciousTarget(m_subject, source))
if (source && m_retargetCooldownTimer == 0.0f && CombatSolver.IsJudiciousTarget(m_subject, source) && (
!m_target || CanRetarget(source)))
{
m_target = source;
GameManager.NotificationSystem.targetDetected.Invoke(this, m_subject);
}
}


💬 Comments (10)
Want to continue the conversation?