public SetDestination ( Vector3 target ) : bool | ||
target | Vector3 | The target point to navigate to. |
return | bool |
void Patrol() { agent.speed = patrolSpeed; if (Vector3.Distance(this.transform.position, waypoints[waypointInd].transform.position) >= 1) { Quaternion newRotation = Quaternion.LookRotation(waypoints[waypointInd].transform.position - this.transform.position); //newRotation.x = 0f; //newRotation.z = 0f; //this.transform.rotation = Quaternion.Slerp(transform.rotation, newRotation, Time.deltaTime * 5f); agent.SetDestination(waypoints[waypointInd].transform.position); } else if (Vector3.Distance(this.transform.position, waypoints[waypointInd].transform.position) <= 1) { // if we're close to the position we want to get to // then it is time to go the next position waypointInd += 1; if (waypointInd >= waypoints.Length) { waypointInd = 0; } } }
public void Flee(Vector3 position) { // Vector3 fleeDirection, newGoal; NavMeshPath path; if (Vector3.Distance(position, this.transform.position) < detectionRadius) { /*fleeDirection = (this.transform.position - position).normalized; * newGoal = this.transform.position + fleeDirection * fleeRadius; * path = new NavMeshPath (); * _agent.CalculatePath (newGoal, path);*/ path = CalculatePath(position); if (path != null) //path.status != NavMeshPathStatus.PathInvalid) { { Debug.Log("valid path"); _agent.SetDestination(path.corners [path.corners.Length - 1]); if (_anim != null) { _anim.SetTrigger("isRunning"); } _agent.speed = 10; _agent.angularSpeed = 500; } else { Debug.Log("invalid path"); } } }
void PickGoalLocation() { lastGoal = agent.destination; GameObject goalPos = GameEnviroment.Singleton.GetRandomGoal(); agent.SetDestination(goalPos.transform.position); }
// Update is called once per frame void Update() { timepo += Time.deltaTime; //ここのGoNectPointがPlayerとの距離が近づいた後も呼ばれてしまっている //ので①の中に入った後は呼ばれないような処理を追加すればいける if (timepo > 20.0f && disance == true) { GotoNextPoint(); timepo = 0; } Vector3 Apos = player.transform.position; Vector3 Bpos = transform.position; float dis = Vector3.Distance(Apos, Bpos); if (dis <= 20.0f) { //① agent.SetDestination(target.position); disance = false; } else if (dis > 20.0f) { disance = true; } }
/// <summary> /// navAgent /// </summary> /// <param name="position"></param> /// <param name="stopDistance"></param> /// <param name="moveSpeed"></param> public void MoveToTarget(Vector3 position, float stopDistance, float moveSpeed) { //通过寻路组件实现 navAgent.SetDestination(position); navAgent.stoppingDistance = stopDistance; navAgent.speed = moveSpeed; }
public void Attack(int num) { if (num == 0) { bonusAttack = Random.Range(0, 2); agent.SetDestination(GameObject.FindGameObjectWithTag("Player").transform.position); transform.LookAt(GameObject.FindGameObjectWithTag("Player").transform); animator.SetTrigger("attack"); attackCount++; } else if (num == 1) { bonusAttack = Random.Range(0, 2); agent.SetDestination(GameObject.FindGameObjectWithTag("Player").transform.position); transform.LookAt(GameObject.FindGameObjectWithTag("Player").transform); animator.SetTrigger("attack2"); attackCount++; } else if (num == 1) { bonusAttack = Random.Range(0, 2); agent.SetDestination(GameObject.FindGameObjectWithTag("Player").transform.position); transform.LookAt(GameObject.FindGameObjectWithTag("Player").transform); animator.SetTrigger("attack3"); attackCount++; } }
void statechange() { NMA.isStopped = false; if (nowstate == 0)//Cruise State { NMA.stoppingDistance = 0; anim.SetInteger("State", 1); NMA.speed = walkSpeed; NMA.SetDestination(waypoints[waypoints_index].position); CruisePosition(); } else if (nowstate == 1)//Chasing State { NMA.destination = player.transform.position; NMA.speed = runSpeed; anim.SetInteger("State", 2); } else if (nowstate == 2)//Attack State { NMA.stoppingDistance = AttackDistance; anim.SetInteger("State", 3); //Debug.DrawLine(transform.position,player.transform.position,Color.red); } else if (nowstate == 3) { NMA.stoppingDistance = RemoteAttackDistance - 1; anim.SetInteger("State", 4); } else if (nowstate == -1) { anim.SetInteger("State", 0); // transform.LookAt(new Vector3(0, -1, 0)); } }
void goHome() { agent.SetDestination(Home.position); goingHome = true; atGrocery = false; atShop = false; }
private void Update() { var otherPlayer = GameObject.FindGameObjectWithTag("OtherPlayer"); if (_enemyHealth.CurrentHealth > 0 && _playerHealth.CurrentHealth > 0) { if (otherPlayer != null) { var toPlayer = Vector3.Distance(_player.position, transform.position); var toOtherPlayer = Vector3.Distance(otherPlayer.transform.position, transform.position); if (toPlayer > toOtherPlayer) { _nav.SetDestination(otherPlayer.transform.position); } else { _nav.SetDestination(_player.position); } } else { _nav.SetDestination(_player.position); } } else { _nav.enabled = false; } }
private void Update() { if (agent.remainingDistance < 1) { ResetAgent(); agent.SetDestination(goalLocations[Random.Range(0, goalLocations.Length)].transform.position); } }
public void Seek(Vector3 location) { if (!agent.isOnNavMesh) { return; } agent.SetDestination(location); }
private void WalkToTarget() { if (agent.remainingDistance < 2 || agent.pathStatus != NavMeshPathStatus.PathComplete) { agent.updateRotation = true; nextTarget = RandomTarget(); agent.SetDestination(nextTarget); } }
private void Following() { if (Vector3.Distance(transform.position, target_obj.transform.position) > 0.25f) { if (target_obj != null) { agent.SetDestination(target_obj.transform.position); } } }
public void Freeze() { agent.SetDestination(transform.position); if (anime != null) { foreach (Animator a in anime) { a.enabled = false; } } frozen = true; }
//------------------------------------------ public IEnumerator AIPatrol() { if (PlayerAudioControl.chaseMusicOn) { StartCoroutine(stopChaseMusic(chaseMusicTimeout)); } float timeToWait = isAngry ? .1f : 1f; yield return(new WaitForSeconds(timeToWait)); seeking = false; ThisAgent.speed = patrolSpeed; //Loop while patrolling while (currentstate == ENEMY_STATE.PATROL) { //Set strict search m_ThisScrLineOfSight.Sensitivity = scr_LineOfSight.SightSensitivity.STRICT; //Chase to patrol position ThisAgent.isStopped = false; ThisAgent.SetDestination(PatrolDestination.position); //Wait until path is computed while (ThisAgent.pathPending) { yield return(null); } //If we can see the target then start chasing if (m_ThisScrLineOfSight.CanSeeTarget) { ThisAgent.isStopped = true; CurrentState = ENEMY_STATE.CHASE; yield break; } //Have we arrived at dest, get new dest // debug -> if (Vector3.Distance(transform.position, PatrolDestination.position) <= ThisAgent.stoppingDistance*1.2f) if (Vector3.Distance(transform.position, PatrolDestination.position) <= ThisAgent.stoppingDistance) { ThisAgent.isStopped = true; //check if current destination is an active gate and set new destination based on that PatrolDestination = newDestination(PatrolDestination); isAngry = false; } //Wait until next frame yield return(null); } }
private void Update() { if (currentAIMode == AIMode.Combat) { if (!agent.enabled) { return; } if (agent.remainingDistance <= agent.stoppingDistance + 0.05f) { animator.SetBool("IsShooting", true); inCover = true; //agent.ResetPath(); transform.LookAt(target); if (Time.time > lastShotTime + timeBetweenShots && inCover) { //Shoot (); lastShotTime = Time.time; } } else { animator.SetBool("IsShooting", false); } } else { if (animator.GetFloat("Speed") > 0 && agent.remainingDistance <= agent.stoppingDistance + 0.05f) { if (marchingPath != null) { currentPathIndex++; if (currentPathIndex < marchingPath.Length) { agent.SetDestination(marchingPath[currentPathIndex]); } } } } AllyControl[] targets = FindObjectsOfType <AllyControl>(); targetsTransform.Clear(); foreach (AllyControl ac in targets) { if (ac.Alive) { targetsTransform.Add(ac.transform); } } targetsTransform.Add(player); }
// Active for Chase void Chase() { // When the enemy is chasing the player I simply wanna set the Enemy's destination to be whereever the player is. agent.SetDestination(player.transform.position); if (Vector3.Distance(transform.position, player.transform.position) > 5.5f) { brain.PushState(Idle, OnIdleEnter, OnIdleExit); } if (withinAttackRange) { brain.PushState(Attack, OnAttackEnter, null); } }
void Start() { nav = GetComponent <NavMeshAgent>(); nav.Warp(this.transform.position); PlayerTower = GameObject.FindGameObjectWithTag("Player Tower"); EnemyTower = GameObject.FindGameObjectWithTag("Enemy Tower"); if (Vector3.Distance(this.transform.position, PlayerTower.transform.position) < Vector3.Distance(this.transform.position, EnemyTower.transform.position)) { targetTower = EnemyTower.transform.position; twr = EnemyTower.GetComponent <TowerBehaviour>().tower; minion.minionType = Minion.MinionType.PLAYER; } else { targetTower = PlayerTower.transform.position; twr = PlayerTower.GetComponent <TowerBehaviour>().tower; minion.minionType = Minion.MinionType.ENEMY; } if (this.gameObject.transform.position.z < 0) { nav.SetDestination(GameObject.FindGameObjectWithTag("LeftBridge").transform.position); } else { nav.SetDestination(GameObject.FindGameObjectWithTag("RightBridge").transform.position); } switch (minion.minionType) { case Minion.MinionType.ENEMY: { var v = this.gameObject.GetComponentsInChildren <Renderer>().ToList(); foreach (var renderer in v) { renderer.material = RedMaterial; } break; } case Minion.MinionType.PLAYER: { var v = this.gameObject.GetComponentsInChildren <Renderer>().ToList(); foreach (var renderer in v) { renderer.material = BlueMaterial; } break; } } }
private void Patroling() { float currDistance = Vector3.Distance(walkPoints[currWalkPoint], transform.position); if (currDistance < 2) { walkPointSet = false; currWalkPoint = (currWalkPoint + 1) % walkPoints.Length; } if (!walkPointSet) { agent.SetDestination(walkPoints[currWalkPoint]); } }
private void setNextWaypoint() { if (currWaypoint >= waypoints.Length - 1) { currWaypoint = 0; } else { currWaypoint++; } if (waypoints.Length != 0) { navMeshAgent.SetDestination(waypoints[currWaypoint].transform.position); } }
/// <summary> /// Walkings around at random. /// </summary> void WalkingAroundRandom() { //for duration of timer timer -= Time.deltaTime; //when timer is over if (timer <= 0) { //new position to go to Vector3 newPos = RandomNavSphere(transform.position, wanderRadius, -1); agent.SetDestination(newPos); //new random timer timer = Random.Range(wanderTimerMin, wanderTimerMax); } }
void MoveAI() { int index = random.Next(1, 4); _navMeshAgentvMesh.SetDestination(waypointsPositions[index - 1]); characterAnimator.SetBool("AI", true); }
public void setDestination(Vector3 newDestination) { // If our new destination is close enough to where we currently are don't do anything if (Vector3.Distance(transform.position, newDestination) <= 1.0f) { // Stop the navmesh agent agent.isStopped = true; // Stop running anim.SetBool("Running", false); return; } anim.SetBool("Running", true); // Set our target position targetPosition = newDestination; // Activate our nav mesh agent and start moving to our destination if (!agent.isActiveAndEnabled) { agent.enabled = true; } agent.isStopped = false; agent.SetDestination(newDestination); }
// Update is called once per frame void Update() { if (posicion.position.x == pointA[0] && posicion.position.z == pointA[2] && gotoB == false) { Debug.Log("entra"); gotoB = true; nav.SetDestination(pointB); } if (posicion.position.x == pointB[0] && posicion.position.z == pointB[2] && gotoB == true) { Debug.Log("no deberia entrar"); gotoB = false; nav.SetDestination(pointA); } }
void Wander() { var dist = Random.Range(WanderDistanceMin, WanderDistanceMax); Destination = tr.position + Random.insideUnitSphere * dist; navMeshAgent.SetDestination(Destination); }
public void checkAnimation() { if (Vector3.Distance(player.position, this.transform.position) < distance) { Vector3 direction = player.position - this.transform.position; direction.y = 0; this.transform.rotation = Quaternion.Slerp(this.transform.rotation, Quaternion.LookRotation(direction), 0.1f); anim.SetInteger("moving", 0); nav = GetComponent <NavMeshAgent>(); nav.isStopped = true; if (direction.magnitude < 15) { nav = GetComponent <NavMeshAgent>(); nav.isStopped = false; anim.SetBool("attack", false); anim.SetBool("trick", true); anim.SetInteger("moving", 1); nav.SetDestination(player.position); } if (direction.magnitude < 5) { nav = GetComponent <NavMeshAgent>(); nav.isStopped = true; anim.SetInteger("moving", 0); anim.SetBool("attack", true); } } }
void Update() { // Nav Mesh Stuff Move = GetComponent <UnityEngine.AI.NavMeshAgent>(); Move.SetDestination(Player.transform.position); // Make Sure The Enemy Is Facing The Player transform.LookAt(Player); // Registering Player Score Total = ScoreCounter1.Coop + ScoreCounter2.Coop + ScoreCounter3.Coop + ScoreCounter4.Coop + ScoreCounter5.Coop; // Movement Speed Increasing Based On Player Score if (Total > 799) { Move.speed = .3f; } if (Total > 1399) { Move.speed = .6f; } if (Total > 1999) { Move.speed = 1.1f; } }
// Update is called once per frame public void StartSkyNet() { //while(failedStatus != true) { agent.speed = (float)speedAgent; finishPoint = prog.EndPT.transform.position; startPoint = prog.StartPT.transform.position; //UnityEngine.Debug.Log("End pos:"+finishPoint); agent.Warp(startPoint); // IF true The AI failed if (!failedStatus) { if (GameObject.Find("NavMeshBaker").GetComponent <NavMeshBaker>().getNavBuilded()) { // Init Start Time // if (flag) { startTime = DateTime.Now; //UnityEngine.Debug.Log(startTime); flag = false; } // AI Movement // agent.SetDestination(finishPoint); } } else { // Set AI speed to 0 if failed agent.velocity = Vector3.zero; } //} }
// Update is called once per frame void Update() { if (transform.position.z > 20) { agent.SetDestination(destination.position); } }
// Update is called once per frame void Update() { // Distance to the target float distance = Vector3.Distance(target.position, transform.position); // If inside the lookRadius if (distance <= lookRadius) { // If within attacking distance if (distance <= agent.stoppingDistance) { // Attack the target FaceTarget(); // Make sure to face towards the target createInversionField(); } else { // Move towards the target agent.SetDestination(target.position); } } CheckDeath(); }