public void RunFrom(AiComponentController controller, Transform from) { Transform transform = controller.transform; // store the starting transform Transform startTransform = transform; //temporarily point the object to look away from the player transform.rotation = Quaternion.LookRotation(transform.position - from.position); //Then we'll get the position on that rotation that's multiplyBy down the path (you could set a Random.range // for this if you want variable results) and store it in a new Vector3 called runTo Vector3 runTo = transform.position + transform.forward * 20; //Debug.Log("runTo = " + runTo); //So now we've got a Vector3 to run to and we can transfer that to a location on the NavMesh with samplePosition. NavMeshHit hit; // stores the output in a variable called hit // 5 is the distance to check, assumes you use default for the NavMesh Layer name NavMesh.SamplePosition(runTo, out hit, 5, 1 << NavMesh.GetNavMeshLayerFromName("Default")); //Debug.Log("hit = " + hit + " hit.position = " + hit.position); // just used for testing - safe to ignore // reset the transform back to our start transform transform.position = startTransform.position; transform.rotation = startTransform.rotation; // And get it to head towards the found NavMesh position controller.navMeshAgent.SetDestination(hit.position); }
private void DoActions(AiComponentController controller) { for (int i = 0; i < actions.Length; i++) { actions [i].Act(controller); } }
public override void Act(AiComponentController controller) { if (controller.isChaseing) { } //controller; }
public override bool Decide(AiComponentController controller) { if (PlayerController.playerTransform != null && controller.brain != null && controller.chaser == null) { List <AiComponent> agents = controller.getAgentsInRange(controller.brain.getSensorRange()); if (agents.Count > 1) { foreach (AiComponent agent in agents) { if (controller.tag == "DOG" && agent.getController().tag == "CAT") { return(false); } } } // if(Vector3.Distance(controller.transform.position,agent.getController().transform.position)<=controller.brain.getSensorRange()) // return false; if (Vector3.Distance(controller.transform.position, PlayerController.playerTransform.position) <= controller.brain.getSensorRange()) { controller.chasing = PlayerController.playerTransform; return(true); } return(false); } return(false); }
public override bool Decide(AiComponentController controller) { if (controller.tag == "CAT" && controller.chaser != null) { return(true); } return(false); }
public override void Act(AiComponentController controller) { // if(checkAttackDistance( controller.chasing, controller.chaser)){ //TODO: start attack animation //TODO: call the damage script onthe target //} RunFrom(controller, controller.chaser); }
public override void Act(AiComponentController controller) { // if(checkAttackDistance( controller.chasing, controller.chaser)){ //TODO: start attack animation //TODO: call the damage script onthe target //} if (controller.chasing != null) { controller.navMeshAgent.SetDestination(controller.chasing.position); } }
public override void Act(AiComponentController controller) { if (temp == null) { temp = new Vector3(); } if (temp == point) { point = controller.getRandomMovementPoint(); } controller.navMeshAgent.SetDestination(point); temp = point; }
private void CheckTransitions(AiComponentController controller) { for (int i = 0; i < transitions.Length; i++) { bool decisionSucceeded = transitions[i].decision.Decide(controller); if (decisionSucceeded) { controller.TransitionToState(transitions[i].trueState); } else { controller.TransitionToState(transitions[i].falseState); } } }
public override bool Decide(AiComponentController controller) { List <AiComponent> agents = controller.getAgentsInRange(controller.brain.getSensorRange()); if (agents.Count > 1) { foreach (AiComponent agent in agents) { if (controller.tag == "DOG" && agent.getController().tag == "CAT") { //TODO: find cat in range controller.chasing = getNearest(controller, agents).getController().transform; agent.getController().chaser = controller.transform; return(true); } } } return(false); }
public override bool Decide(AiComponentController controller) { System.Collections.Generic.List <AiComponent> agents = controller.getAgentsInRange(controller.brain.getSensorRange()); if (agents.Count > 1) { foreach (AiComponent agent in agents) { if (agent.getController().tag == "CAT") { return(false); } } } if (Vector3.Distance(controller.transform.position, PlayerController.playerTransform.position) <= controller.brain.getSensorRange()) { return(false); } return(true); }
private AiComponent getNearest(AiComponentController controller, List <AiComponent> agents) { AiComponent near = null; foreach (AiComponent agent in agents) { if (agent.getController().tag == "CAT") { if (near == null) { near = agent; } else { if (Vector3.Distance(controller.transform.position, agent.getController().transform.position) <= Vector3.Distance(controller.transform.position, near.getController().transform.position)) { near = agent; } } } } return(near); }
public abstract bool Decide(AiComponentController controller);
public void UpdateState(AiComponentController controller) { DoActions(controller); CheckTransitions(controller); }
public override bool Decide(AiComponentController controller) { return(false); }
public override void Act(AiComponentController controller) { }
public abstract void Act(AiComponentController controller);