[Custom Decision Script] Get Target Current Health %
Feb 14, 2019 20:31:13 GMT
Invector, komposite, and 1 more like this
Post by cursedereaper on Feb 14, 2019 20:31:13 GMT
Hey,
I wrote the custome decision "Get current Targets Health" which could be used to switch into a more agressive state like less blocking and more attacking if the target has little Health. And this Thread is only to share this with everyone.
I hope you like it.
I also want to include the get current target Stamina as well because it could be something one could use to switch into a more agressiv behavior or that an Enemy with low ammo will only shoot a target with low stamina (or throw a granate on an target with low stamina via trigger events).
And a small note: It is quite easy to write the decision that only refer to parts from invector scripts (PS: I'm actually an Artist XD). I still have problems to include bools of script my programmer made.
I wrote the custome decision "Get current Targets Health" which could be used to switch into a more agressive state like less blocking and more attacking if the target has little Health. And this Thread is only to share this with everyone.
I hope you like it.
using UnityEngine;
namespace Invector.vCharacterController.AI.FSMBehaviour
{
public class AICheckTargetHealth : vStateDecision
{
public override string defaultName
{
get
{
return "Check Target Health";
}
}
public enum vCheckValue
{
Equals, Less, Greater, NoEqual
}
public vCheckValue checkValue = vCheckValue.NoEqual;
public float value;
public override bool Decide(vIFSMBehaviourController fsmBehaviour)
{
return CheckValue(fsmBehaviour);
}
protected virtual bool CheckValue(vIFSMBehaviourController fsmBehaviour)
{
if (fsmBehaviour == null) return false;
float health = fsmBehaviour.aiController.currentTarget.currentHealth;
switch (checkValue)
{
case vCheckValue.Equals:
return health == value;
case vCheckValue.Less:
return health < value;
case vCheckValue.Greater:
return health > value;
case vCheckValue.NoEqual:
return health != value;
}
return false;
}
}
}
I also want to include the get current target Stamina as well because it could be something one could use to switch into a more agressiv behavior or that an Enemy with low ammo will only shoot a target with low stamina (or throw a granate on an target with low stamina via trigger events).
And a small note: It is quite easy to write the decision that only refer to parts from invector scripts (PS: I'm actually an Artist XD). I still have problems to include bools of script my programmer made.