void Start() { Base = GameObject.FindGameObjectWithTag("Base"); player = GameObject.FindGameObjectWithTag("Player"); target = playerManager.instance.player.transform; // basePlayer = BaseManager.instance.Base.transform;// geting the bases singleton nav.GetComponent <NavMeshAgent>(); originalSpeed = maxSpeed; three_point_wavespawner.Enemiesalive++; // nav.destination = basePlayer.position; }
void OnTriggerEnter(Collider other) { agent.GetComponent <NPCMove>().setFailedStatus(true); TimeSpan res = GameObject. FindGameObjectWithTag("Stop"). GetComponent <FinishRun>(). getResultTime(); UnityEngine.Debug.Log(res); }
public static bool SetPath2D(this NavMeshAgent nmAgent, NavMeshPath path) { #if UNITY_EDITOR var helper = nmAgent.GetComponent <NavAgentHelper>(); if (helper != null) { helper.lastDestination2D = path.corners.Last(); } #endif return(nmAgent.SetPath(path)); }
void Start() { agent_2 = ai_2.GetComponent <NavMeshAgent>(); agent_2.GetComponent <NavMeshAgent>().SetDestination(p2_1.transform.position); randTime = Random.Range(0, 50); cams.Cam1.enabled = true; //seenRat = false; patrolling = true; a2hiding = false; //restart = false; }
public static void SetShieldHolder(this NavMeshAgent nmAgent, bool isShieldHolder = true) { var helper = nmAgent.GetComponent <NavAgentHelper>(); if (!helper) { Debug.LogError("No NavAgentHelper is attached to " + nmAgent.name); return; } helper.agentZ = isShieldHolder ? NavigationMain.current.shieldHoldersZ : NavigationMain.current.standardAgentsZ; }
void LateUpdate() { // Choose the next destination point when the agent gets // close to the current one. if (aracaMiCarpti) { return; } float distance = Vector3.Distance(player.transform.position, transform.position); if (distance <= 2f && !code.GetComponent <gameControl> ().carDrivingMode&& !code.GetComponent <gameControl> ().oturmaMode) { //2 metre yakınında ajanı durdurup bize baktır agent.isStopped = true; //purr agent.GetComponents <AudioSource> () [1].enabled = true; agent.GetComponents <AudioSource> () [0].enabled = false; if (!birKereSesCalis) { birKereSesCalis = true; agent.GetComponent <Animator> ().SetBool("durArtik", true); } RotateTowards(player.transform); } else { agent.isStopped = false; birKereSesCalis = false; //mioo agent.GetComponents <AudioSource> () [0].enabled = true; agent.GetComponents <AudioSource> () [1].enabled = false; agent.GetComponent <Animator> ().SetBool("durArtik", false); if (!agent.pathPending && agent.remainingDistance < 0.5f) { GotoNextPoint(); } } }
// Update is called once per frame void Update() { agent.GetComponent <Animator>().SetFloat("speed", agent.velocity.magnitude); if (Input.GetMouseButtonDown(0)) { RaycastHit hit; if (Physics.Raycast(this.GetComponent <Camera>().ScreenPointToRay(Input.mousePosition), out hit)) { agent.SetDestination(hit.point); } } }
void Update() { if (agent.pathPending || !agent.GetComponent <NavMeshAgent>().enabled || interactScript.onConversation) { return; } updateRVO(); move(); checkArrivedCorner(); checkArrived(); checkBench(); }
// Update is called once per frame void Update() { //If we dont look at him for x sec or we are too far, he changes its position after x sec if (PostProcessBzz.timeNotLooking > 8) { PostProcessBzz.timeNotLooking = 0; Spawn(); } //Keep on facing player transform.LookAt(new Vector3(mainCamera.transform.position.x, transform.position.y, mainCamera.transform.position.z)); if (isEnemySeen) { enemy.GetComponent <NavMeshAgent>().enabled = false; } else { enemy.GetComponent <NavMeshAgent>().enabled = true; enemy.SetDestination(player.transform.position); } }
public void GetInteractionValues(NavMeshAgent playerNavAgent, GameObject interactedObject) { playerNavAgent_ = playerNavAgent; playerCotroller_ = playerNavAgent.GetComponent <PlayerController>(); if (playerCotroller_ == null) { Debug.LogWarning("No se encontro el controlador del jugador a traves del NavAgent"); } interactedObject_ = interactedObject; _hasInteracted = false; }
public override BTNodeStatus Run() { if (isAtPlayer.active) { agent.GetComponent <NavMeshAgent>().enabled = false; rotateAroundPlayer(); return(BTNodeStatus.Success); } else { return(BTNodeStatus.Failed); } }
void Update() { navMeshAgent.GetComponent <Animator>().SetFloat("velocidad", navMeshAgent.velocity.magnitude); if (Input.GetKeyDown(KeyCode.Mouse0) && cam.isActiveAndEnabled) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { navMeshAgent.SetDestination(hit.point); } } }
void wander() { agent.isStopped = false; Vector3 searchPos = enemyMovement.transform.position + (Random.insideUnitSphere * agent.GetComponent <SphereCollider> ().radius); searchPos.y = 0.6f; //agent.destination = searchPos; setDestination(searchPos); Debug.Log(searchPos + ", " + agent.destination + ", " + searchTimer.getElapsedTime() + ", " + agent.isStopped); lookTimer.start(); }
void GoToStart1() { if (patrolling == true) { agent_2.GetComponent <NavMeshAgent> ().SetDestination(p2start.transform.position); Debug.Log("agent 2 going to start"); } }
private void StartArena() { // TODO: florian // BTW: you can check if a bug is inside the arena in the same way I did with the players in the "OnTriggerEnter" function // Get Spawner from Wisp agent with GetComponent if (_miniBossChest) { _wispAgent.GetComponent <SwarmSpawner>().ArenaStartSpawning(this, _insidePolygon, true); } else { _wispAgent.GetComponent <SwarmSpawner>().ArenaStartSpawning(this, _insidePolygon, false); } // Call Spawn Function // -> This should start the spawning progress as it is so far, but with the new Polygon Check. Also, a counter so it only spawns until a total number is reached. // For Beetle AI: Increase Player Search Radius over time (currently done, but maybe slower and to a larger radius?) // Also, no more Kill Range, instead reenable them walking towards the wisp. But only to the outer general area, at which point the player attention should trigger! // With player attention and wisp attention, both should have a certain time until they trigger to give the bugs some time to formate. }
/* void ShowGUI() * { * //distanceBetweenEnemyAndPlayer = Vector3.Distance(this.transform.position, player.position); * orcChase.lookRadius = Vector3.Distance(this.transform.position, player.position); * * if (distance < orcChase.lookRadius) * { * GUI.enabled = true; * * } * else * { * GUI.enabled = false; * } * }*/ public void TakeDamage(int amount) { CurrentHealth -= amount; if (CurrentHealth <= 0) { animis.SetTrigger("isDead"); orcChase.GetComponent <OrcChase>().enabled = false; agent.GetComponent <NavMeshAgent>().enabled = false; sinking = true; Destroy(orc, destroyTime); } }
// Update is called once per frame void Update() { if (inRangeSee()) { mRunning = true; chase(); } if (inRangeAttack()) { mAgent.GetComponent <NavMeshAgent>().isStopped = true; mRunning = false; mAttack = true; } else { mAgent.GetComponent <NavMeshAgent>().isStopped = false; mAttack = false; } mAnimator.SetBool("running", mRunning); mAnimator.SetBool("canAttack", mAttack); }
// Use this for initialization void Start() { goalLocations = GameObject.FindGameObjectsWithTag("TraitorGoal"); agent = this.GetComponent <UnityEngine.AI.NavMeshAgent>(); agent.SetDestination(goalLocations[Random.Range(0, goalLocations.Length)].transform.position); agent.speed = Random.Range(1, 2); agent.acceleration = Random.Range(1, 8); animations = agent.GetComponent <Animation>(); animations.PlayQueued("Walk"); player = GameObject.FindGameObjectWithTag("Player"); //anim = this.GetComponent<Animator> (); //anim.SetTrigger ("isWalking"); }
void OnCollisionEnter(Collision collision) { Debug.Log("Collide"); // force is how forcefully we will push the player away from the enemy. float force = 300; // If the object we hit is the ball if (collision.gameObject.tag == "ball") { Debug.Log("player hits the ball!"); // Calculate Angle Between the collision point and the player Vector3 dir = collision.contacts[0].point - transform.position; // We then get the opposite (-Vector3) and normalize it dir = -dir.normalized; // And finally we add force in the direction of dir and multiply it by force. // This will push back the player GameObject ball = GameObject.FindWithTag("ball"); ball.GetComponent <Rigidbody>().AddForce(dir * force); navMeshAgent.isStopped = true; navMeshAgent.GetComponent <Rigidbody>().velocity = Vector3.zero; navMeshAgent.GetComponent <Rigidbody>().angularVelocity = Vector3.zero; GetComponent <Rigidbody>().velocity = Vector3.zero; GetComponent <Rigidbody>().angularVelocity = Vector3.zero; // while (GetComponent<Rigidbody>().velocity.magnitude != 0) // { // GetComponent<Rigidbody>().velocity = Vector3.zero; // GetComponent<Rigidbody>().angularVelocity = Vector3.zero; // } } else if (collision.gameObject.tag == "enemy") { Debug.Log("players atacks enemy!"); } }
public void SpawnAgent() { GameObject obj = null; // Set Target of the MainAgent if (MainAgent == null) { // Spawn the gameObject obj = (GameObject)Instantiate(Resources.Load("Player/ent_pidgeon"), SpawnPoint.position, Quaternion.identity); obj.GetComponent <NavMeshBehaviour>().MyAgent = obj.GetComponent <NavMeshAgent>(); MainAgent = obj.GetComponent <NavMeshAgent>(); MainAgent.GetComponent <SphereCollider>().enabled = true; MainAgent.stoppingDistance = 0; MainAgent.avoidancePriority = 0; MainAgent.GetComponent <NavMeshBehaviour>().isMain = true; MainAgent.SetDestination(SpawnPoint.position); } else { // Spawn the gameObject Vector2 randomPos = Random.insideUnitCircle * 2; obj = (GameObject)Instantiate(Resources.Load("Player/ent_pidgeon"), MainAgent.transform.position + new Vector3(randomPos.x, MainAgent.transform.position.y, randomPos.y), Quaternion.identity); obj.GetComponent <NavMeshBehaviour>().MyAgent = obj.GetComponent <NavMeshAgent>(); } obj.name = "ent_pigeon" + AllAgents.Count.ToString(); obj.transform.parent = GameManager.Level.EntityContainer; // Add to the list of agents in the manager AllAgents.Add(obj.GetComponent <NavMeshAgent>()); }
// Update is called once per frame void Update() { //when our player is within the defined radius, the enemy should chase the player object if (Vector3.Distance(m_playerObject.transform.position, gameObject.transform.position) < m_detectRadius) { //enemy > follows player m_agent.GetComponent <Renderer>().material = m_chasingMaterial; m_agent.SetDestination(m_playerObject.transform.position); return; } //else / otherwise it should stay put //or if the enemy already chased me, the object should go to its position //enemy is in idle state m_agent.GetComponent <Renderer>().material = m_idleMaterial; //when patrolling enemy is in idle //before it goes to initial pos //it tracks the last pos of playerObject if (m_agent.remainingDistance < 0.5f) { m_agent.SetDestination(target: GetNextDestination()); } }
public void Hurt(float value) { hp -= value; hpUI.SetHpPercent(hp / nowhp); hp = hp <= 0 ? 0 : hp; if (hp == 0) { agent.GetComponent <Collider>().enabled = false; var go = Instantiate(explodePrefab, transform.position, transform.rotation); Destroy(go, 1f); GetMoney.moneyAdd(gold); level.EnemyDead(); Destroy(hpUI.gameObject); Destroy(this.gameObject); } }
private void DeployTroops() { troopsDeployed = true; rigidbody.isKinematic = true; troops.transform.SetParent(null); troops.enabled = true; Vector3 troopLocalPosition = troops.transform.localPosition; Vector3 point; if (RandomPoint(transform.position, 3, out point)) { troops.Warp(point); } troops.GetComponent <Enemy>().SetupEnemy(transform, troopLocalPosition); }
void OnCollisionEnter(Collision collider) { int deathBlow = 8; if (collider.gameObject.tag == "RightSword" || collider.gameObject.tag == "LeftSword") { if (!isHit && dead != true) { isHit = true; var magnitude = 2000; var force = transform.position - collider.transform.position; force.Normalize(); gameObject.GetComponent <Rigidbody>().AddForce(force * magnitude); soundPlayer.volume = 1f; soundPlayer.PlayOneShot(soundManager.pedeHurt); VibrationManager.singleton.TriggerVibration(20, 2, 155, OVRInput.Controller.RTouch); ++numberCollisions; } if (numberCollisions >= deathBlow) { dead = true; gameObject.GetComponent <AudioSource>().Stop(); pedeAnimate.SetTrigger("pedeDie"); soundPlayer.PlayOneShot(soundManager.pedeHurt); StartCoroutine("deadPedeTimer"); agent.updatePosition = false; agent.GetComponent <Rigidbody>().isKinematic = true; numberCollisions = 0; deathBlow = 30; } } if (collider.gameObject.tag == "Player") { var magnitude = 1500; var force = transform.position - collider.transform.position; force.Normalize(); gameObject.GetComponent <Rigidbody>().AddForce(force * magnitude); } }
void Start() { anim = GetComponent <Animator>(); agentEnemy.GetComponent <NavMeshAgent>(); player = GameObject.FindGameObjectWithTag("Player"); playerPosition = player.transform; NavMeshHit closestHit; if (NavMesh.SamplePosition(agentEnemy.transform.position, out closestHit, 500f, NavMesh.AllAreas)) { agentEnemy.transform.position = closestHit.position; } else { Debug.LogError("Could not find position on NavMesh!"); } }
// Use this for initialization void Start() { m_bossAgent = GetComponent <NavMeshAgent>(); m_bossAgent.GetComponent <NavMeshAgent>().enabled = false; m_weaponController = GetComponent <WeaponController>(); m_barrels = GetComponent <DestructibleObject>(); #region ///Lerp Attempt //Starts the boss on the right side of the tracks m_boss.transform.position = m_rightSide.transform.position; //Gets the distance between the left side and right side of the tracks m_journeyLength = Vector3.Distance(m_leftSide.position, m_rightSide.position); #endregion }
// Update is called once per frame void Update() { /* if (Input.touchCount > 0 && Input.touches[0].phase == TouchPhase.Began) // start touching * { * Ray ray = Camera.main.ScreenPointToRay(Input.touches[0].position); // 產生觸碰點到場景上的ray * * * if (Physics.Raycast(ray, out RaycastHit hitInfo)) //取得射綫碰撞資訊 * { * GameObject target = hitInfo.collider.gameObject; //取得碰撞物 * * MeshRenderer mr = target.GetComponent<MeshRenderer>(); //取得碰撞物的render * * if (mr.sharedMaterial != a1)//比較材質是否是a1,不是的話就換,是的話換a2 * mr.sharedMaterial = a1; * else * mr.sharedMaterial = a2; * * * } * * * }*/ if (Input.touchCount > 0 && Input.touches[0].phase == TouchPhase.Began) // start touching { Ray ray = Camera.main.ScreenPointToRay(Input.touches[0].position); // 產生觸碰點到場景上的ray if (Physics.Raycast(ray, out RaycastHit hitInfo)) //取得射綫碰撞資訊 { GameObject army = hitInfo.collider.gameObject; //取得碰撞物 Rigidbody rb = agent.GetComponent <Rigidbody>();//取得碰撞物的物理 //rb.AddForce(new Vector3(0, 05f));// 推 if (army.tag == "Groud") //如果碰撞物是地板 { agent.SetDestination(hitInfo.point); //讓Agent走去碰撞點 } } } }
void ToggleAgentAttributeVisibility() { try { for (int i = 0; i < AgentList.Count; i++) { NavMeshAgent t = AgentList[i]; referenceObject = t.gameObject; //Canvas referenceCanvas = referenceObject.GetComponent<Canvas>(); //referenceCanvas.SetActive(false); t.GetComponent <Canvas>().enabled = false; } } catch (Exception e) { print("error"); } }
public override NodeState Evaluate() { if (agent.isOnNavMesh) { agent.SetDestination(target.position); animator.SetBool(ZombieAnimatorVariables.AttackingBool, false); animator.SetFloat(ZombieAnimatorVariables.MovingName, ZombieAnimatorVariables.Run); state = NodeState.SUCCES; } else { state = NodeState.FAILURE; } agent.GetComponent <ZombieAI>().SetIndicatorColor(Color.yellow); return(state); }
void Start() { float heightOffset = Random.Range(-heightRange, heightRange); float widthOffset = Random.Range(-widthRange, widthRange); float speedOffset = Random.Range(-speedRange, speedRange); Vector3 scaleOffset = new Vector3(widthOffset, heightOffset, widthOffset); bool isFemale = (Random.value > 0.5f); if (isFemale) { agent.transform.localScale = new Vector3(femaleWidth, femaleHeight, femaleWidth); } agent.transform.localScale += scaleOffset; agent.GetComponent <NavMeshAgent>().speed += speedOffset; }