public void Execute(Entity e) { AIEntity entity = (AIEntity)e; // check point 1 { // damaged first if (entity.triggerDamage) { entity.target = entity.triggerDamage; entity.triggerDamage = null; entity.Event = eEntityState.Search; return; } // check target in sight if (Facade_AI.DetectTarget(entity.property, entity.property.tb.sightRange, out entity.target)) { Debug.Log("- Detect palyer!!"); // check runaway condition (life) if (entity.Ai.IsRunawayCondition()) { entity.Event = eEntityState.Runaway; return; } // check distance for attacking or Vector3 distance = entity.target.transform.position - entity.property.transform.position; if (distance.magnitude < entity.property.tb.attackRange) { entity.Event = eEntityState.Attack; } else { entity.Event = eEntityState.Chase; } return; } } // check point 2 { // change next moving position if (!entity.Ai.IsMoving) { if (Facade_NavMesh.RandomRangePoint( entity.property.transform.position, entity.property.tb.wander_min_range, entity.property.tb.wander_max_range, out entity.destination)) { entity.Ai.agent.destination = entity.destination; } } } }
public void Execute(Entity e) { AIEntity entity = (AIEntity)e; // check point 1 { // check runaway condition (life) if (entity.Ai.IsRunawayCondition()) { entity.Event = eEntityState.Runaway; return; } // check still in attack range ( not in sight) RaycastResult result = Facade_AI.IsRaycastHit(entity.property, entity.target, entity.property.tb.attackRange); if (result != RaycastResult.FoundTarget) { // replace target and mode change to attack Vector3 distance = entity.property.DistanceFrom(entity.target); if (distance.magnitude < entity.property.tb.chaseRange) { entity.Event = eEntityState.Chase; } else { entity.Event = eEntityState.Search; } return; } } // check point 2 { // attack processing if (elapsedTime > entity.property.tb.attack_interval) { elapsedTime = 0; // attack entity.Ai.OnAttack(entity.target); } if (entity.Ai.animator) { entity.Ai.animator.SetBool("attack", true); } // increase elapse time elapsedTime += Time.deltaTime; } float slerpTime = 10.0f; // look at the target Vector3 look = entity.property.DistanceFrom(entity.target).normalized; entity.property.transform.forward = Vector3.Lerp(entity.property.transform.forward, look, slerpTime * Time.deltaTime); }
public void Execute(Entity e) { AIEntity entity = (AIEntity)e; // check point 1 { // check runaway condition (life) if (entity.Ai.IsRunawayCondition()) { entity.Event = eEntityState.Runaway; return; } // check target in sight (Search Range) if (Facade_AI.DetectTarget(entity.property, entity.property.tb.searchRange, out entity.target)) { Debug.Log("- Detect palyer!!"); // check distance for attacking or Vector3 distance = entity.target.transform.position - entity.property.transform.position; if (distance.magnitude < entity.property.tb.attackRange) { entity.Event = eEntityState.Attack; } else { entity.Event = eEntityState.Chase; } return; } } // check point 2 { // check reach them and something if (!entity.Ai.IsMoving) { entity.Event = eEntityState.Wander; } } }
public void Execute(Entity e) { AIEntity entity = (AIEntity)e; // check point 1 { // check runaway condition (life) if (entity.Ai.IsRunawayCondition()) { entity.Event = eEntityState.Runaway; return; } // check target in sight ( attack range) if (entity.target && entity.target.isAlive) { RaycastResult result = Facade_AI.IsRaycastHit(entity.property, entity.target, entity.property.tb.attackRange); if (result == RaycastResult.FoundTarget) { entity.Ai.agent.isStopped = true; entity.Event = eEntityState.Attack; return; } // blocked sight if (result == RaycastResult.BlockedTarget) { Vector3 distance = entity.property.DistanceFrom(entity.target); if (distance.magnitude < entity.property.tb.chaseRange) { entity.Ai.agent.destination = entity.target.transform.position; entity.Ai.agent.isStopped = false; return; } } } else { ObjectProperty target; if (Facade_AI.DetectTarget(entity.property, entity.property.tb.attackRange, out target)) { // replace target and mode change to attack entity.Ai.agent.isStopped = true; entity.target = target; entity.Event = eEntityState.Attack; return; } } } //check point 2 { // follow target if it is in chaseRange if (entity.target && entity.target.isAlive) { Vector3 distance = entity.property.DistanceFrom(entity.target); if (distance.magnitude < entity.property.tb.chaseRange) { entity.Ai.agent.destination = entity.target.transform.position; return; } } } // check reach them and something if (!entity.Ai.IsMoving) { entity.Event = eEntityState.Wander; } }