public override Status Update() { // Get the renderer UnityEngine.AI.NavMeshAgent agent = gameObject.Value != null?gameObject.Value.GetComponent <UnityEngine.AI.NavMeshAgent>() : null; // Validate members if (agent == null) { return(Status.Error); } agent.Resume(); return(Status.Success); }
/// <summary>Initialization Method of MoveToPosition.</summary> /// <remarks>Check if there is a NavMeshAgent to assign a default one and assign the destination to the NavMeshAgent the given position.</remarks> public override void OnStart() { navAgent = gameObject.GetComponent <UnityEngine.AI.NavMeshAgent>(); if (navAgent == null) { Debug.LogWarning("The " + gameObject.name + " game object does not have a Nav Mesh Agent component to navigate. One with default values has been added", gameObject); navAgent = gameObject.AddComponent <UnityEngine.AI.NavMeshAgent>(); } navAgent.SetDestination(target); #if UNITY_5_6_OR_NEWER navAgent.isStopped = false; #else navAgent.Resume(); #endif }
public override void OnStart() { if (target == null) { Debug.LogError("The movement target of this game object is null", gameObject); return; } targetTransform = target.transform; navAgent = gameObject.GetComponent <UnityEngine.AI.NavMeshAgent>(); if (navAgent == null) { Debug.LogWarning("The " + gameObject.name + " game object does not have a Nav Mesh Agent component to navigate. One with default values has been added", gameObject); navAgent = gameObject.AddComponent <UnityEngine.AI.NavMeshAgent>(); } navAgent.SetDestination(targetTransform.position); navAgent.Resume(); }
public override Status Update() { if (!memory) { return(Status.Error); } ICover nearstCover = NearstCover(); if (nearstCover == null) { return(Status.Failure); } agent.SetDestination(nearstCover.pos); agent.Resume(); return(Status.Running); }
void Patrol_Enter() { agent.Resume(); // initially move towards the closest waypoint float distance = Mathf.Infinity; float localDistance; for (int i = 0; i < waypoints.Length; ++i) { if ((localDistance = Vector3.Magnitude(transform.position - waypoints[i].transform.position)) < distance) { distance = localDistance; waypointIndex = i; } } waypointReachedTime = -1; agent.SetDestination(Target()); }
public override Status Update() { BaseAIParameters param = self.GetComponent <BaseAIParameters>(); if (!param || !param.destinationEnable) { return(Status.Failure); } if (Vector3.Distance(self.transform.position, param.destination) < 2) { return(Status.Success); } UnityEngine.AI.NavMeshAgent agent = self.GetComponent <UnityEngine.AI.NavMeshAgent>(); agent.SetDestination(param.destination); agent.Resume(); return(Status.Running); }
public override Status Update() { //BaseAIParameters param = self.GetComponent<BaseAIParameters>(); //if (!param || !param.destinationEnable) //{ // return Status.Failure; //} //if (Vector3.Distance(self.transform.position, param.destination) < param.endSeekingDistance) //{ // return Status.Success; //} Memory memory = self.GetComponent <Memory>(); if (!memory) { return(Status.Failure); } ITarget[] targets = memory.AllTargets(); bool hasTarget = targets.Length > 0; if (hasTarget) { ITarget target = targets[0]; IMemorable memorable = target as IMemorable; IMemorableItem memItem = memory.Find(memorable); Vector3 destination = memItem.lastOccurPosition; UnityEngine.AI.NavMeshAgent agent = self.GetComponent <UnityEngine.AI.NavMeshAgent>(); agent.SetDestination(destination); agent.Resume(); return(Status.Running); } else { UnityEngine.AI.NavMeshAgent agent = self.GetComponent <UnityEngine.AI.NavMeshAgent>(); agent.Stop(); return(Status.Failure); } }
/// <summary> /// This method updates the NavMesh Agent thus allowing the enemy to move. /// If the player is within the enemy's range then the enemy will move towards /// the player. Otherwhise he will stop. If the player is within melee range /// then the enemy will always face the player. /// </summary> void Movement() { distance = Vector3.Distance(player.position, transform.position); if (Physics.Raycast(collider.transform.TransformPoint(collider.center), playerDir, out hitInfo, viewLenght) && hitInfo.transform.tag == "Player" && distance > attackDistance) { Debug.Log("Player is in range and the enemy is following him"); nav.SetDestination(player.position); nav.Resume(); } else if (distance < attackDistance) { Debug.Log("The enemy is close enough to attack"); nav.Stop(true); transform.LookAt(player.transform); } else if (distance > viewDistance) { nav.Stop(true); } }
} // SetPlayerInSight void StartPatrolling() { General.Logger.LogDetail("AI", "StartPatrolling", "Entering function. patrolPath.patrolTimer: " + patrolInfo.patrolTimer + ", navMeshAgent.remainingDistance: " + navMeshAgent.remainingDistance + ", navMeshAgent.stoppingDistance: " + navMeshAgent.stoppingDistance); float angle = FindRadian(transform.forward, navMeshAgent.desiredVelocity, transform.up); navMeshAgent.Resume(); navMeshAgent.speed = patrolInfo.patrolSpeed; if (Mathf.Abs(angle) < patrolInfo.deadZone) { transform.LookAt(transform.position + navMeshAgent.desiredVelocity); } // if animator.SetBool(ANIMATION_IS_PATROLLING, true); if (navMeshAgent.remainingDistance < navMeshAgent.stoppingDistance) { patrolInfo.patrolTimer += Time.deltaTime; if (patrolInfo.patrolTimer > patrolInfo.patrolWaitTime) { if (patrolInfo.patrolWayPoints.Length - 1 == patrolInfo.wayPointIndex) { patrolInfo.wayPointIndex = 0; } // if else { patrolInfo.wayPointIndex++; } // else patrolInfo.patrolTimer = 0.0f; } // if } // if else { patrolInfo.patrolTimer = 0.0f; } // else navMeshAgent.destination = patrolInfo.patrolWayPoints[patrolInfo.wayPointIndex].position; General.Logger.LogDetail("AI", "StartPatrolling", "Exiting function. patrolPath.patrolWayPoints.Length: " + patrolInfo.patrolWayPoints.Length + ", patrolPath.wayPointIndex: " + patrolInfo.wayPointIndex); } // StartPatrolling
public override void OnStart() { navMeshAgent.speed = speed.Value; navMeshAgent.angularSpeed = angularSpeed.Value; navMeshAgent.Resume(); }
void goDestination_Enter() { agent.Resume(); agent.SetDestination(target.transform.position); }
void Flee_Enter() { agent.Resume(); }