void DoActions(ref BrainAIComponent brain, ref EcsEntity entity) { for (int i = 0; i < actions.Length; i++) { actions[i].Act(ref brain, ref entity); } }
void Scan(ref BrainAIComponent brain, ref EcsEntity entity) { if (brain.Agent.enabled) { brain.Agent.isStopped = true; brain.Agent.enabled = false; } var turnSpeed = brain.EnemyStats.SearchingTurnSpeed * Time.deltaTime; var rb = entity.Get <MoveComponent>().RB; rb.transform.Rotate(new Vector3(0f, rb.transform.rotation.y + turnSpeed, 0f)); }
void CheckTransitions(ref BrainAIComponent brain) { for (int i = 0; i < transitions.Length; i++) { bool decisionSucceded = transitions[i].Decision.Decide(ref brain); if (decisionSucceded) { brain.TransitionToState(transitions[i].TrueState); } else { brain.TransitionToState(transitions[i].FalseState); } } }
void Patrol(ref BrainAIComponent brain, ref EcsEntity entity) { var agent = brain.Agent; agent.enabled = true; agent.destination = brain .Waitpoints[brain.NextWayPoint] .position; var distToPoint = (agent.destination - agent.transform.position).magnitude; if (agent.remainingDistance <= agent.stoppingDistance && !agent.pathPending) { brain.NextWayPoint = (brain.NextWayPoint + 1) % brain.Waitpoints.Length; } }
void Attack(ref BrainAIComponent brain, ref EcsEntity entity) { #if DEBUG Debug.DrawRay(brain.Eyes.position, brain.Eyes.forward * brain.EnemyStats.AttackRange, Color.red); #endif if (Physics.SphereCast(brain.Eyes.position, brain.EnemyStats.LookSphereCastRadius, brain.Eyes.forward, out RaycastHit hit, brain.EnemyStats.AttackRange, brain.PlayerLayer)) { if (brain.IsCheckCountDownElapsed(brain.EnemyStats.AttackRate)) { Fire(ref entity); } } }
bool Look(ref BrainAIComponent brain) { #if DEBUG Debug.DrawRay(brain.Eyes.position, brain.Eyes.forward * brain.EnemyStats.LookRange, Color.green); #endif if (Physics.SphereCast(brain.Eyes.position, brain.EnemyStats.LookSphereCastRadius, brain.Eyes.forward, out RaycastHit hit, brain.EnemyStats.LookRange, brain.PlayerLayer)) { brain.ChaseTarget = hit.transform; return(true); } return(false); }
public abstract void Act(ref BrainAIComponent brain, ref EcsEntity entity);
public override void Act(ref BrainAIComponent brain, ref EcsEntity entity) { Chase(ref brain, ref entity); }
void Chase(ref BrainAIComponent brain, ref EcsEntity entity) { brain.Agent.enabled = true; brain.Agent.destination = brain.ChaseTarget.position; }
public override bool Decide(ref BrainAIComponent brain) { return(brain.ChaseTarget.gameObject.activeSelf); }
public void UpdateState(ref BrainAIComponent brain, ref EcsEntity entity) { DoActions(ref brain, ref entity); CheckTransitions(ref brain); }
public abstract bool Decide(ref BrainAIComponent brain);
public override bool Decide(ref BrainAIComponent brain) { return(Scan(ref brain)); }
bool Scan(ref BrainAIComponent brain) { return(brain.IsCheckCountDownElapsed(brain.EnemyStats.SearchDuration)); }