← Back to all addons

Fluent Retarget (AI) 🐾

Posted by Mr.Titan on May 24, 2025 at 10:14 PM

GameplayExperimentalFeature3.0 Verified
smart 7 eyesshaking 4 💡 3

Quick 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)

BellBlitzKing May 25, 2025 at 02:46 AM
Big brain in action!
❤️ 1
Deleted User May 25, 2025 at 03:34 AM
Honestly
❤️ 1
Mr.Titan May 25, 2025 at 04:42 AM
Pritty simple, actually, but appreciated! ♥️
Zuko Sep 16, 2025 at 09:48 PM
@Mr.Titan this works with sohos waypoint script?
Mr.Titan Sep 16, 2025 at 09:53 PM
Not sure, but at first glance i don’t think so. This extends the standard code, the waypoint seems to be a new thing. But no one better then sohos tp tell you
Zuko Sep 16, 2025 at 09:55 PM
i mean, this affects the normal ai controller right
Zuko Sep 16, 2025 at 09:55 PM
it will not conflict with ai waypoint controller
Zuko Sep 16, 2025 at 09:56 PM
if i want just to use the normal ai controller in a few monsters
Zuko Sep 16, 2025 at 09:56 PM
i made my question wrong
Zuko Sep 17, 2025 at 12:07 AM
tested, it workd fine with sohos add on 👌

Want to continue the conversation?