FSM AI integration WIP

mrgyarmati

New member
Hi. I'm trying to integrate the Invector FSM AI. My script is based on magique's EmeraldAI integration script. But if I shoot the AI, that is receive the damage and the character stack in aim position and I get an Null reference exeption error. I think something I missed.
Here is the script:

C#:
using UnityEngine;
using Opsive.Shared.Events;
using Invector;

public class OpsiveBridge : MonoBehaviour
{
    private vIHealthController _aiHealth;
    public vDamage damage;

    private void Awake()
    {
        _aiHealth = GetComponent<vIHealthController>();

        EventHandler.RegisterEvent<float, Vector3, Vector3, GameObject, object, Collider>(gameObject, "OnObjectImpact",
            OnObjectImpact);
    }

    private void OnObjectImpact(float amount, Vector3 position, Vector3 forceDirection, GameObject attacker, object attackerObject, Collider hitCollider)
    {
        Debug.Log("Position " + position);
        Debug.Log("Force Direction " + forceDirection);
        Debug.Log("Attacker " + attacker);
        Debug.Log("Attacker Object " + attackerObject);
        Debug.Log("Collider " + hitCollider);
        damage.damageValue = (int)amount;
        if (_aiHealth != null && _aiHealth.isDead == false)
        {
            Debug.Log("FSM AI damaged by " + amount);
            _aiHealth.TakeDamage(damage);
        }
    }

    public void OnDestroy()
    {
        EventHandler.UnregisterEvent<float, Vector3, Vector3, GameObject, object, Collider>(gameObject, "OnObjectImpact", OnObjectImpact);
    }
}

NullReferenceError.png
 
Ok, I found the solution for how to damage the Invector FSM AI. Here is the script. Still in progress because the hit reaction need more work I think also still need the AI damage the player.

C#:
using UnityEngine;
using Opsive.Shared.Events;
using Invector;

public class OpsiveBridge : MonoBehaviour
{
    private vIHealthController _aiHealth;

    private void Awake()
    {
        _aiHealth = GetComponent<vIHealthController>();

        EventHandler.RegisterEvent<float, Vector3, Vector3, GameObject, object, Collider>(gameObject, "OnObjectImpact",
            OnObjectImpact);
    }

    private void OnObjectImpact(float amount, Vector3 position, Vector3 forceDirection, GameObject attacker, object attackerObject, Collider hitCollider)
    {
        /*Debug.Log("Position " + position);
        Debug.Log("Force Direction " + forceDirection);
        Debug.Log("Attacker " + attacker.transform);
        Debug.Log("Attacker Object " + attackerObject);
        Debug.Log("Collider " + hitCollider);*/
        
        if (_aiHealth != null && _aiHealth.isDead == false)
        {
            Debug.Log("FSM AI damaged by " + amount);
            var aiDamage = new vDamage();
            aiDamage.receiver = gameObject.transform;
            aiDamage.sender = attacker.transform;
            aiDamage.hitPosition = position;
            aiDamage.hitReaction = true;
            aiDamage.damageValue = (int)amount;
            
            gameObject.ApplyDamage(aiDamage);
        }
    }

    public void OnDestroy()
    {
        EventHandler.UnregisterEvent<float, Vector3, Vector3, GameObject, object, Collider>(gameObject, "OnObjectImpact", OnObjectImpact);
    }
}
 
Ok, I found the solution for how to damage the Invector FSM AI. Here is the script. Still in progress because the hit reaction need more work I think also still need the AI damage the player.

C#:
using UnityEngine;
using Opsive.Shared.Events;
using Invector;

public class OpsiveBridge : MonoBehaviour
{
    private vIHealthController _aiHealth;

    private void Awake()
    {
        _aiHealth = GetComponent<vIHealthController>();

        EventHandler.RegisterEvent<float, Vector3, Vector3, GameObject, object, Collider>(gameObject, "OnObjectImpact",
            OnObjectImpact);
    }

    private void OnObjectImpact(float amount, Vector3 position, Vector3 forceDirection, GameObject attacker, object attackerObject, Collider hitCollider)
    {
        /*Debug.Log("Position " + position);
        Debug.Log("Force Direction " + forceDirection);
        Debug.Log("Attacker " + attacker.transform);
        Debug.Log("Attacker Object " + attackerObject);
        Debug.Log("Collider " + hitCollider);*/
       
        if (_aiHealth != null && _aiHealth.isDead == false)
        {
            Debug.Log("FSM AI damaged by " + amount);
            var aiDamage = new vDamage();
            aiDamage.receiver = gameObject.transform;
            aiDamage.sender = attacker.transform;
            aiDamage.hitPosition = position;
            aiDamage.hitReaction = true;
            aiDamage.damageValue = (int)amount;
           
            gameObject.ApplyDamage(aiDamage);
        }
    }

    public void OnDestroy()
    {
        EventHandler.UnregisterEvent<float, Vector3, Vector3, GameObject, object, Collider>(gameObject, "OnObjectImpact", OnObjectImpact);
    }
}
You alive?))
 
Top