// Update is called once per frame void Update() { //target = GameObject.FindGameObjectWithTag("Player").GetComponent<Transform>(); // Distance to the target distance = Vector3.Distance(target.position, transform.position); // If inside the lookRadius if (distance <= lookRadius) { // Move towards the target agent.SetDestination(target.position); velocity.y = 0.9f; shouldMove = true; //velocity.magnitude > 0.5f && agent.remainingDistance > agent.radius; shouldFight = false; // Update animation parameters // If within attacking distance if (distance <= agent.stoppingDistance) { shouldFight = true; shouldMove = false; FaceTarget(); // Make sure to face towards the target } // Update animation parameters animator.SetBool("move", shouldMove); animator.SetBool("fight", shouldFight); animator.SetFloat("vx", velocity.x); animator.SetFloat("vy", velocity.y); } if (distance > lookRadius && shouldMove == true) { if (agent.hasPath) { agent.ResetPath(); } shouldMove = false; animator.SetBool("move", shouldMove); } }
private void Update() { var position = transform.position; _camera.transform.position = position; if (!_canControl) { ResetVelocity(); if (_canEnd && _navMeshAgent.remainingDistance < 0.5f) { GameManager.instance.NextScene(); } if (_canDropLantern && _bodyAnimator.GetCurrentAnimatorStateInfo(0).IsName("BodyLantern")) { GameManager.instance.DropLantern(); _lights.SetActive(false); GoToBed(); } if (!_navMeshAgent.hasPath || !(_navMeshAgent.remainingDistance < 0.1f)) { return; } _canDropLantern = true; _navMeshAgent.ResetPath(); _legsAnimator.SetBool(IsWalking, _isWalking = false); _bodyAnimator.SetBool(IsWalking, _isWalking); _bodyAnimator.SetTrigger(Lantern); } else { _playerMovement = new Vector3( (Input.GetAxis("Horizontal") > 0.2f || Input.GetAxis("Horizontal") < -0.2f ? Input.GetAxis("Horizontal") : 0), 0, (Input.GetAxis("Vertical") > 0.2f || Input.GetAxis("Vertical") < -0.2f ? Input.GetAxis("Vertical") : 0) ); MovementAnimation(_playerRigidBody.velocity); } }
private void WyszukajCel() { czyMamCel = false; znalezioneObiekty = Physics.OverlapSphere(transform.position, promienWyszukiwania); foreach (Collider obiekt in znalezioneObiekty) { if (obiekt.CompareTag("Gracz")) { ZacznijIsc(obiekt.transform.position); czyMamCel = true; print("Znalaz³em Cel"); } } if (!czyMamCel) { mojNavMeshAgent.isStopped = true; mojNavMeshAgent.ResetPath(); ZatrzymajSie(); } }
public override void OnStart() { agent.ResetPath(); Debug.Log($"MoveToTarget Is Target null {Target.Value == null}"); Vector3 lastClosest = Target.Value.transform.position; float closestDistance = float.MaxValue; foreach (Vector3 position in GetPositionListAround(Target.Value.transform.position, 2f, 10)) { float distance = Vector3.Distance(transform.position, position); if (distance < closestDistance) { closestDistance = distance; lastClosest = position; } } if (lastClosest != Destination) { agent.SetDestination(lastClosest); Destination = lastClosest; } }
void Update() { if (hp < 0) { this.gameObject.SetActive(false); return; } isover = Director.getInstance().currentSceneController.isGameOver(); if (!isover) { target = Director.getInstance().currentSceneController.getPlayerPos(); //向玩家坦克移动 NavMeshAgent agent = GetComponent <NavMeshAgent>(); agent.SetDestination(target); } else {//游戏结束,停止寻路 NavMeshAgent agent = GetComponent <NavMeshAgent>(); agent.velocity = Vector3.zero; agent.ResetPath(); } }
void TogglePatrolPathing() { if (chaseStopped == false) { pathingScript.active = false; } else { pathingScript.active = true; } if ((agent.destination - agent.transform.position).magnitude <= chaseStopRange && headingPlayerOne.magnitude > chaseRange && headingPlayerTwo.magnitude > chaseRange && chaseStopped == false || (agent.destination - agent.transform.position).magnitude <= chaseStopRange && playerOneObstructed && playerTwoObstructed && chaseStopped == false) { agent.SetDestination(gameObject.GetComponent <GuardPatrol>().currentCheckpoint.transform.position); chaseStopped = true; returning = true; } if ((agent.destination - agent.transform.position).magnitude <= chaseStopRange && chaseStopped == true) { agent.ResetPath(); returning = false; } }
private void MoveTowardsPlayer() { if (_pickedUpItem != null) { return; } if (Vector3.Distance(_navMeshAgent.destination, _targetPlayer.transform.position) > 1) { if (_navMeshAgent.isOnNavMesh) { _navMeshAgent.ResetPath(); } } if (_navMeshAgent.hasPath || _navMeshAgent.pathPending) { return; } _navMeshAgent.SetDestination(_targetPlayer.transform.position); }
public void MovePNC(Vector3 target) { // Enable the NavMeshAgent characterAgent.enabled = true; // Rotate the player to look at the mouse point // Un-comment to enable look at. transform.LookAt(target); // Check for a left mouse press if (Input.GetButtonDown("Fire1") && !isJumping) { // Reset the agents current path characterAgent.ResetPath(); // Give the agent a new destination characterAgent.destination = target; } }
void AdjustMovement() { if (currentState == EnemyMovementStates.JustRight) { nav.ResetPath(); } else if (currentState == EnemyMovementStates.TooFar) { nav.SetDestination(player.position); } else if (currentState == EnemyMovementStates.TooClose) { Vector3 dirToPlayer = transform.position - player.transform.position; Vector3 newPos = transform.position + dirToPlayer; nav.SetDestination(newPos); } if (anim != null) { anim.SetFloat("Walk", nav.velocity.magnitude); } }
void Update() { agent.ResetPath(); agent.destination = new Vector3(0, player.position.z, player.position.y); if (agent.pathPending) { dist = Vector3.Distance(transform.position, new Vector3(0, player.position.z, player.position.y)); } else { dist = agent.remainingDistance; } speedSet = dist * 4 + 1; if (speedSet > 200) { agent.speed = 200; } else { agent.speed = speedSet; } }
//竜巻の中での処理 public void Vortex() { if (isInTheVortex) { return; } isInTheVortex = true; vortexPos = transform.position; vortexRotation = transform.rotation; if (tornado != null) { tornado.Play(); } initialized = false; ag.ResetPath(); rb.isKinematic = false; rb.useGravity = false; rb.mass = 0; rb.constraints = RigidbodyConstraints.None; rb.AddTorque(Vector3.up, ForceMode.Impulse); gravityScale = -10; }
private IEnumerator Attack(IAttackableByEnemy target) { if (currentAttackCooldown > 0) { yield break; } currentAttackCooldown = float.MaxValue; StopCoroutine(patrolCoroutine); navMeshAgent.speed = defaultSpeed * 2f; navMeshAgent.angularSpeed = 360; bool reached = false; while (!reached) { foreach (var item in Physics.OverlapSphere(target.transform.position, 1.9f)) { if (item == myCollider) { reached = true; break; } } navMeshAgent.SetDestination(target.transform.position); yield return(null); } navMeshAgent.updateRotation = false; StartCoroutine(LockOnRotation(target.transform)); navMeshAgent.ResetPath(); navMeshAgent.isStopped = true; animator.SetTrigger(EnemyCreatureAnimations.AttackTrigger); tempAttackTarget = target; }
private void Update() { if (!following) { return; } if (Vector3.Distance(playerPosition, player.transform.position) > 2) { playerPosition = player.transform.position; NavMeshHit hit; if (NavMesh.SamplePosition(playerPosition, out hit, 3, -1)) { agent.destination = hit.position; } } if (Vector3.Distance(playerPosition, transform.position) < 2) { agent.ResetPath(); } anim.SetFloat("speed", agent.velocity.magnitude / 6); }
void FixedUpdate() { anim_Controller.speed = animationSpeed; if (Vector3.Distance(Target.transform.position, transform.position) <= Range) { navMeshAgent.destination = Target.transform.position; } else { if (navMeshAgent.hasPath) { //Debug.Log("I should stop moving"); navMeshAgent.ResetPath(); } } if (navMeshAgent.remainingDistance <= navMeshAgent.stoppingDistance) { m_Running = false; anim_Controller.SetBool("running", m_Running); //navMeshAgent.updatePosition = false; } else { m_Running = true; anim_Controller.SetBool("running", m_Running); } if (Vector3.Distance(Target.transform.position, transform.position) <= AttackRange) { if (canStartNewAttack) { StartCoroutine(Attack(1f)); } } }
private void RollBack(Dictionary <Action, GameObject> backUpStatusList) { //print("ROLLING BACK"); foreach (KeyValuePair <Action, GameObject> item in backUpStatusList) { switch (item.Key.Name) { case "MOVE": NavMeshAgent agent = null; if (item.Value.name == "ROVER1") { agent = rover1.GetComponent <NavMeshAgent>(); } else { agent = rover2.GetComponent <NavMeshAgent>(); } agent.ResetPath(); agent.gameObject.transform.position = item.Value.transform.position; break; case "TAKE_SAMPLE": //if (item.Value.activeSelf == true) // takeSample.SetActive(true); //else // takeSample.SetActive(false); break; case "DROP_SAMPLE": break; case "TAKE_IMAGE": break; } } }
public void SetDestination(Vector3 destination, bool forced = false) { if (Speed <= 0f) { return; } if (navMeshAgent == null) { InitNavMeshAgent(); } if (navMeshAgent.destination == destination) { return; } if (forced && OnForceDestinationSet != null) { OnForceDestinationSet(); } isCurrentDestinationForced = forced; navMeshAgent.isStopped = true; navMeshAgent.ResetPath(); navMeshAgent.isStopped = false; CurrentTargetPosition = destination; if (CurrentTarget != null && CurrentTarget.IsFrendly(this)) { navMeshAgent.stoppingDistance = 0; } else { navMeshAgent.stoppingDistance = AttackRange + stoppingThreshold; } navMeshAgent.SetDestination(destination); IsMoving = true; }
void FixedUpdate() { //Find a player if there is no target if (player == null) { player = FindObjectOfType <PlayerController>().gameObject; } //Shoot if possible timeSinceLastShot += fixedDeltaTime; if (Vector3.Magnitude(transform.position - player.transform.position) <= weaponRange && timeSinceLastShot >= reloadTime) { timeSinceLastShot = 0f; Shoot(player.transform.position, transform.position); } //Determine movement if (avoidanceMode == false && (transform.position - player.transform.position).magnitude < weaponRange / 2) { avoidanceMode = true; agent.ResetPath(); } else if (avoidanceMode == true && (transform.position - player.transform.position).magnitude > weaponRange) { avoidanceMode = false; agent.SetDestination(player.transform.position); } if (avoidanceMode == true && agent.remainingDistance < 1) { float randomModifierX = Random.Range(-(weaponRange / 2), weaponRange / 2); float randomModifierY = Random.Range(-(weaponRange / 2), weaponRange / 2); Vector3 randomPosition = transform.position; randomPosition.x += randomModifierX; randomPosition.y += randomModifierY; agent.SetDestination(randomPosition); } }
void Update() { if (!gm.isGameOver() && !gm.countDown) { if (Input.GetMouseButtonDown(0)) { RaycastHit hit; if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 100)) { agent.destination = hit.point; } } } else { agent.ResetPath(); } if (agent.hasPath) { animator.speed = 1; if (cross == null) { cross = (GameObject)Instantiate(Resources.Load("Prefabs/Cross"), agent.destination, agent.transform.rotation); } else { cross.transform.position = agent.destination; } } else { animator.speed = 0; Destroy(cross); } }
public IEnumerator MoveEnemy(Vector3 target) { cameraManager.ChangeMovable(); cameraManager.StartCoroutine("FollowEnemy", gameObject); navAgent.SetDestination(target); //set destination to mouse position audio.Play(); yield return(new WaitForSeconds(movementTime)); //wait for how long this player can move audio.Stop(); navAgent.ResetPath(); //stop movement when time is up cameraManager.ChangeMovable(); //make the camera stop following the player cameraManager.ResetCamera(); CheckCollision(); TurnEnded(); turnManager.CheckEnemyTurns(); }
void Walk() { if (Vector3.Distance(Player.transform.position, transform.position) > 1.5f) { // transform.LookAt(Player.transform); // transform.Translate(Vector3.forward * Time.deltaTime * mov_speed); zombieAnim.ZombieWalk(); StartCoroutine(Check()); agent.SetDestination(Player.transform.position); } else { if (attack_cooldown <= 0 && isAlive) { Player.GetComponent <Movement>().take_damage(5.0f); Debug.Log("Attacking.."); zombieAnim.ZombieAttack(); attack_cooldown = attack_speed; } agent.ResetPath(); } attack_cooldown -= Time.deltaTime; }
public override void Update() { NavMeshAgent agent = Recipient.GetComponent <NavMeshAgent>(); // Go 1 unit in front of the other agent if (!initDancePosition) { initDancePosition = true; Vector3 position = otherAgent.transform.position + otherAgent.transform.forward * 2; agent.SetDestination(position); } if (agent.remainingDistance < 0.1f && !agent.pathPending && !reachedDancePosition) { agent.ResetPath(); reachedDancePosition = true; } if (reachedDancePosition) { Recipient.transform.Rotate(new Vector3 { x = 0, y = -2, z = 0 }, Space.World); } }
void Update() { AnimationControls(); if (!hasDestination) { hasDestination = true; currentNavMeshTarget = chaseTarget.transform.position; NavigationAgent.SetDestination(currentNavMeshTarget); } if (hasDestination) { //if (Vector3.Distance(transform.position, currentNavMeshTarget) > 15f) timer += Time.deltaTime; if (timer > UpdateTargetFrequency) { timer = 0; hasDestination = false; NavigationAgent.ResetPath(); } } }
public void IdleMovement() { if (!agent.hasPath) { agent.CalculatePath(Random.insideUnitSphere * 10 + transform.position, currentPath); if (currentPath.status == NavMeshPathStatus.PathComplete) { agent.SetPath(currentPath); } else { //currentPath = null; } } else { if (agent.remainingDistance < 0.5f) { agent.ResetPath(); //currentPath = new NavMeshPath(); } } }
void Update() { gameover = GameDirector.getInstance().currentSceneController.isGameOver(); if (!gameover) { target = GameDirector.getInstance().currentSceneController.getPlayerPos(); if (getHp() <= 0 && recycleEvent != null) { recycleEvent(this.gameObject); } else { NavMeshAgent agent = GetComponent <NavMeshAgent>(); agent.SetDestination(target); } } else { NavMeshAgent agent = GetComponent <NavMeshAgent>(); agent.velocity = Vector3.zero; agent.ResetPath(); } }
void Update() { if (isExploding) { BlowUp(); } else { if (onChase) { if (Vector3.Distance(gameObject.transform.position, player.transform.position) > minDistance) { Follow(); } else { navMeshAgent.isStopped = true; navMeshAgent.ResetPath(); isExploding = true; } } } }
private void OnTriggerEnter(Collider other) { // If it reaches a portal, warp to a random other portal if (!warping && other.CompareTag("Portal")) { Debug.Log("Entered Portal"); Portal p = other.gameObject.GetComponent <Portal>(); agent.isStopped = true; agent.ResetPath(); // Make sure it doesn't warp again after it warps in to another trigger warping = true; // Make sure we warp into a valid navmesh location WarpToLocation(p.GetRandomPortal().transform.position); //agent.Warp(p.GetRandomPortal().transform.position); warping = false; //Debug.Log(p.name); } }
public void StopAgent() { isPathing = false; if (target) { prevTarget = target; } target = null; cc.iK?.EnableIk(); if (agent.isOnNavMesh && agent.hasPath) { agent.ResetPath(); } // if(cc.rbChar) // cc.rbChar.rb.isKinematic = false; if (!pathTarget) { return; } pathTarget.SetActive(false); // pathTarget.transform.SetParent(null); }
void OnCollisionEnter(Collision other) { if (other.gameObject.tag == "Player" && PlayerController.playerCaught == false) { agent.Stop(); agent.ResetPath(); caughtPlayer = true; PlayerController.playerCaught = true; gameObject.GetComponent <AILines>().speech.text = gameObject.GetComponent <AILines>().caughtLines[Random.Range(0, gameObject.GetComponent <AILines>().caughtLines.Length)]; //FieldofView Variables: gameObject.GetComponent <FieldOfView>().isChasing = false; FieldOfView.isSpotting = false; waitBeforePatrolResumes = 3.75f; //gameObject.GetComponent<AILines>().speech.text = ""; //SendPlayerToJail(); } }
void Update() { gameover = SceneController.getInstance().isGameOver(); if (!gameover) { if (getHp() <= 0) { this.gameObject.SetActive(false); } else { NavMeshAgent agent = GetComponent <NavMeshAgent>(); target = SceneController.getInstance().getPlayerPosition(); agent.SetDestination(target); } } else { NavMeshAgent agent = GetComponent <NavMeshAgent>(); agent.velocity = Vector3.zero; agent.ResetPath(); } }
// Update is called once per frame void Update() { Debug.Log(Vector3.Distance(robot.transform.position, waypoints[currWaypoint].transform.position)); if (Vector3.Distance(robot.transform.position, waypoints[currWaypoint].transform.position) < 1) { agent.ResetPath(); currWaypoint++; agent.SetDestination(waypoints[currWaypoint].transform.position); if (currWaypoint == 1) { rightArrow.SetActive(true); } else if (currWaypoint == 2) { leftArrow.SetActive(true); rightArrow.SetActive(false); } else { leftArrow.SetActive(false); } } }