Reset or Restart AI agent after it dies [Solved]
Feb 12, 2020 15:49:00 GMT
Invector and noir like this
Post by indennis on Feb 12, 2020 15:49:00 GMT
Currently i'm using Unity 2019.3, Invector 2.5.0. and FSM 1.1.0.
I load the AI-spawn scene example, and everything works as it should.
I created a small script that should bring back the AI to life after 10 seconds.
I put the script on the AI-agent, I load this script in the vControlMelee -> OnDead event,
and I have turned of "Remove components after die"
The problem is that the AI agent does not stand up anymore when using "Death By" -> "animation"
The AI agent does get his health back, and I see that the "isDead" boolean is turned to false, and the AI agent does rotate towards the player, but he stays on the ground and does not get up. <- This is now fixed / working :D
If I change the "Death By" -> to "Ragdoll", it works only for the first time, so after dead the AI-agent falls to the floor, and after 10 seconds he stands back up, but then when he dies a second time, the AI-agent does not fall to the floor anymore. <- This still not works
-- Edit
The code below is now working, so far no problems.
It seems that when you use "ResetRagdoll" anywhere, the "ragdolled" bool in vRagdoll does not turn to false.
Only adding health changes the "ragdolled" value and starts the "ResetRagdoll" somewhere.
I load the AI-spawn scene example, and everything works as it should.
I created a small script that should bring back the AI to life after 10 seconds.
I put the script on the AI-agent, I load this script in the vControlMelee -> OnDead event,
and I have turned of "Remove components after die"
The problem is that the AI agent does not stand up anymore when using "Death By" -> "animation"
The AI agent does get his health back, and I see that the "isDead" boolean is turned to false, and the AI agent does rotate towards the player, but he stays on the ground and does not get up. <- This is now fixed / working :D
If I change the "Death By" -> to "Ragdoll", it works only for the first time, so after dead the AI-agent falls to the floor, and after 10 seconds he stands back up, but then when he dies a second time, the AI-agent does not fall to the floor anymore. <- This still not works
-- Edit
The code below is now working, so far no problems.
It seems that when you use "ResetRagdoll" anywhere, the "ragdolled" bool in vRagdoll does not turn to false.
Only adding health changes the "ragdolled" value and starts the "ResetRagdoll" somewhere.
using UnityEngine;
using Invector.vCharacterController;
using Invector.vCharacterController.AI;
public class ResetAI : MonoBehaviour
{
public vAIMotor aiMotor;
public vRagdoll _ragdoll;
public void StartReset()
{
Invoke("Reset_AI",10f);
}
void Reset_AI()
{
if (aiMotor.deathBy == vAIMotor.DeathBy.Animation)
{
_ragdoll.iChar.ChangeHealth(100);
aiMotor.ResetRagdoll();
aiMotor.animator.SetBool("isDead", false);
aiMotor.triggerDieBehaviour = false;
}
else if (aiMotor.deathBy == vAIMotor.DeathBy.AnimationWithRagdoll)
{
_ragdoll.isActive = true;
_ragdoll.iChar.ChangeHealth(100);
aiMotor.animator.SetBool("isDead", false);
aiMotor.triggerDieBehaviour = false;
}
else if (aiMotor.deathBy == vAIMotor.DeathBy.Ragdoll)
{
_ragdoll.isActive = true;
_ragdoll.iChar.ChangeHealth(100);
aiMotor.triggerDieBehaviour = false;
}
}
}