public void WarpPlayer() { agent.Warp(ActivePlatform.position); scoreMng.TimeValue -= 10; }
public void WarpMeAgentto(Transform argDest) { // print("_A_0_C WarpMeAgentto to " + argDest.parent.name); agent.Warp(argDest.position); }
//Pacman death public void returnToInitialPosition() { agent.Warp(initialPosition); transform.rotation = initialRotation; }
void Start() { GameObject NavMesh = new GameObject("NavMesh"); NavMesh.transform.position = transform.position; navmeshAgent = NavMesh.AddComponent <NavMeshAgent> (); navmeshAgent.Warp(transform.position); //nav =new GameObject("navAgent",typeof(NavMeshAgent)).GetComponent<NavMeshAgent>(); //nav.transform.position = transform.position; if (GameDataManager.GetCurrentDifficulty() == Difficulty.Easy) { MAX_FIND_DISTANT = 150; } MaxHealth = Health; //EAS.Health = Health; //EAS.MyTeam = Team; //EAS.TankName = TankName; //EAS.TankScript = TankScript; TankScript.GetComponent <TankFire>().IsOnLine = true; TankScript.GetComponent <TankFire> ().SetAiMode(); //TankScript.GetComponent<MouseTurret> ().AITurret = true; transform.parent.GetComponentInChildren <TankFire> ().InitSystem(); tankFire = TankScript.GetComponent <TankFire> (); tankFire.UseGravity = false; playerTracksController = GetComponent <PlayerTracksController> (); playerTracksController.enableUserInput = false; playerTracksController.isBot = true; // if (GameDataManager.GetVehicleType (TankName) == VehicleType.TD) { // isTurretLess = true; //} Identity MyIdentity = GetComponent <Identity> (); if (GameDataManager.OfflineMode) { ViewPoint = CreateViewPoint(); ViewPoint.transform.SetParent(transform); Invoke("SwtichToNormalMode", 5); navmeshAgent.radius = 4.5f; navmeshAgent.obstacleAvoidanceType = ObstacleAvoidanceType.MedQualityObstacleAvoidance; ControlByLocal = true; InvokeRepeating("AIState", 0, 1); if (GameDataManager.OfflineMode) { MyIdentity.Init(transform.root.GetComponent <TankInitSystem> ().ownerTeam, InstanceNetType.GameNetWorkBotClient); playerTracksController.SetWheels(true, true, true); } else { playerTracksController.SetWheels(true, false, false); } } else { ControlByLocal = false; playerTracksController.SetWheels(false, false, false); } gameObject.SendMessage("GetOwnerInfo"); StartCoroutine(AttackPlayer()); }
public void Warp(Vector3 pos) { nav.Warp(pos); state = WOState.Nothing; }
public override void Start() { agent = gameObject.GetComponent <NavMeshAgent>(); agent.Warp(new Vector3(transform.position.x, .59f, transform.position.y)); ConstructionManager.availableConShips.Add(this); }
public void teleport(Vector3 pos) { agent.Warp(pos); setSleep(false); }
void Start() { startingPosition = new Vector3(12.8f, 2.2f, 6.7f); agent = GetComponent <NavMeshAgent>(); agent.Warp(startingPosition); }
public override void TeleportTo(Vector3 position) { emerald.StartingDestination = position; agent.Warp(position); agent.SetDestination(position); }
// Start is called before the first frame update void Start() { Agent.Warp(transform.position); }
public override void setPosition(Vector3 postion) { m_navMeshAgent.Warp(postion); }
// Update is called once per frame void Update() { SadnessC = gameController.sadnessComplete; AngerC = gameController.angerComplete; FearC = gameController.fearComplete; Item = gameController.item; if (this.name == "Father" && !birdMovement.playerIn && AngerC && !AngerMoved) { nav.Warp(angerDest.position); AngerMoved = true; anim.SetBool("End", true); } if (this.name == "Daughter" && !birdMovement.playerIn && FearC && !FearMoved) { nav.Warp(fearDest.position); FearMoved = true; anim.SetBool("End", true); } if (this.name == "Son" && !birdMovement.playerIn && SadnessC && !SadnessMoved) { nav.Warp(sadnessDest.position); SadnessMoved = true; anim.SetBool("End", true); } if (Input.GetMouseButtonDown(0) && Time.timeScale == 1 && !playerMovement.talking) { RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit)) { if (Vector3.Distance(player.transform.position, this.transform.position) < 2.0f) { if (hit.transform.gameObject.tag == "Npc") { switch (this.name) { case "Father": if (Item) { flowchart.SendFungusMessage("AngerGotItem"); gameController.item = false; } else if (SadnessC && FearC && AngerC) { flowchart.SendFungusMessage("GameCompleted"); } else if (AngerC) { flowchart.SendFungusMessage("AngerGotItem"); } else if (FearC && !SadnessC) { flowchart.SendFungusMessage("AngerFear"); gameController.angerItem.SetActive(true); } else if (SadnessC && !FearC) { flowchart.SendFungusMessage("AngerSadness"); gameController.angerItem.SetActive(true); } else if (SadnessC && FearC) { flowchart.SendFungusMessage("AngerBoth"); gameController.angerItem.SetActive(true); } else { flowchart.SendFungusMessage("AngerOnly"); gameController.angerItem.SetActive(true); } break; case "Daughter": if (Item) { flowchart.SendFungusMessage("FearGotItem"); gameController.item = false; } else if (SadnessC && FearC && AngerC) { flowchart.SendFungusMessage("GameCompleted"); } else if (FearC) { flowchart.SendFungusMessage("FearGotItem"); } else if (AngerC && !SadnessC) { flowchart.SendFungusMessage("FearAnger"); gameController.fearItem.SetActive(true); } else if (SadnessC && !AngerC) { flowchart.SendFungusMessage("FearSadness"); gameController.fearItem.SetActive(true); } else if (SadnessC && AngerC) { flowchart.SendFungusMessage("FearBoth"); gameController.fearItem.SetActive(true); } else { flowchart.SendFungusMessage("FearOnly"); gameController.fearItem.SetActive(true); } break; case "Son": if (Item) { flowchart.SendFungusMessage("SadnessGotItem"); gameController.item = false; } else if (SadnessC && FearC && AngerC) { flowchart.SendFungusMessage("GameCompleted"); } else if (SadnessC) { flowchart.SendFungusMessage("SadnessGotItem"); } else if (FearC && !AngerC) { flowchart.SendFungusMessage("SadnessFear"); gameController.sadnessItem.SetActive(true); } else if (AngerC && !FearC) { flowchart.SendFungusMessage("SadnessAnger"); gameController.sadnessItem.SetActive(true); } else if (AngerC && FearC) { flowchart.SendFungusMessage("SadnessBoth"); gameController.sadnessItem.SetActive(true); } else { flowchart.SendFungusMessage("SadnessOnly"); gameController.sadnessItem.SetActive(true); } break; } } } } } }
private void Awake() { _navMeshAgent = GetComponent <NavMeshAgent>(); _navMeshAgent.Warp(transform.position); }
public override void SetPosition(FixVector3 pos) { agent.transform.position = pos.vector3; agent.Warp(pos.vector3); }
public void SaveOrReload() { navMeshAgent.Warp(GetSpawnPointInArea(GetTargetArea()).position); TransitionTo <Patrol>(); }
public void WarpToPosition(Vector2 position) { m_NavMeshAgent.Warp(new Vector3(position.x, position.y, 0.0f)); }
protected virtual void NavWarp() { nav.Warp(transform.position); }
private void spawnMove() { isSpawn = true; agent.Warp(transform.position); }
public void timeOut() { agent.Warp(EndBuilding.transform.position); }
// Update is called once per frame void Update() { if (Input.GetKey(KeyCode.LeftArrow)) //左 // agent.SetDestination(agent.transform.position + Vector3.left * speed.z);// { agent.Move(Vector3.left * speed.z); } else if (Input.GetKey(KeyCode.UpArrow)) { agent.Move(Vector3.back * speed.z); // agent.SetDestination(agent.transform.position + Vector3.back* speed.z); } else if (Input.GetKey(KeyCode.DownArrow)) { agent.Move(Vector3.forward * speed.z); // agent.SetDestination(agent.transform.position + Vector3.forward* speed.z); } else if (Input.GetKey(KeyCode.RightArrow)) //下 { agent.Move(Vector3.right * speed.z); // agent.SetDestination(agent.transform.position + Vector3.right* speed.z); } else if (Input.GetKey(KeyCode.C)) { } Vector3?dest = null; if (Input.GetKey(KeyCode.D)) //左 { moveState |= MoveState.Normal; dest = agent.transform.position + Vector3.left * speed.z; // // agent.Move(Vector3.left * speed.z); } else if (Input.GetKey(KeyCode.W)) { moveState |= MoveState.Normal; // agent.Move(Vector3.back* speed.z); dest = agent.transform.position + Vector3.back * speed.z; } else if (Input.GetKey(KeyCode.S)) { moveState |= MoveState.Normal; // agent.Move(Vector3.forward* speed.z); dest = agent.transform.position + Vector3.forward * speed.z; } else if (Input.GetKey(KeyCode.A)) //下 { moveState |= MoveState.Normal; // agent.Move(Vector3.right* speed.z); dest = agent.transform.position + Vector3.right * speed.z; } if (Input.GetKey(KeyCode.Space)) { if (jumpTime == 0f) { jumpTime = 0f; } moveState |= MoveState.Jump; if (teleport != null) //传送到其他地方 { moveState |= MoveState.Teleport; moveState &= ~MoveState.Normal; agent.updatePosition = false; teleportPos = teleport.curCollider == teleport.start ? teleport.endPos : teleport.startPos; } } if ((moveState & MoveState.Normal) != MoveState.NONE) { if (dest != null) { agent.SetDestination(dest.Value); // if(agent.CalculatePath(dest.Value, curPath)){ // agent.SetPath(curPath); // } } } if ((moveState & MoveState.Teleport) != MoveState.NONE) { if (transform.position != teleportPos) { transform.position = Vector3.MoveTowards(transform.position, teleportPos, agent.speed * Time.deltaTime); } else { agent.Warp(transform.position); agent.updatePosition = true; moveState |= MoveState.Normal; moveState &= ~MoveState.Teleport; } } // NavMeshLink link; // link. if ((moveState & MoveState.Jump) != MoveState.NONE) { var y = jumpVel * jumpTime - gravity * jumpTime * jumpTime; jumpTime += Time.deltaTime; if (jumpTime > 0.1f && y < 0f) { moveState &= ~MoveState.Jump; y = 0f; jumpTime = 0f; } character.GetChild(0).localPosition = new Vector3(0, y, 0); } if (Input.mouseScrollDelta.y != 0f) { scrollDelta += Input.mouseScrollDelta.y; z += Input.mouseScrollDelta.y; z = Mathf.Max(z, minZ); z = Mathf.Min(z, maxZ); } // scrollDelta -= var temp = character.position; temp.z = z; cam.transform.position = temp; }
/// <summary> /// プレイヤーの移動処理 /// </summary> private void PlayerMove(bool fixedUpdate) { bool isAccess; try { mode = PlayState.playState.gameMode; isAccess = true; } catch { isAccess = false; } if (isAccess) { mode = PlayState.playState.gameMode; } // カメラの向いている方向を取得 Vector3 cameraForward = Vector3.Scale(PlayerCamera.transform.forward == Vector3.up ? -PlayerCamera.transform.up : PlayerCamera.transform.forward == Vector3.down ? PlayerCamera.transform.up : PlayerCamera.transform.forward, new Vector3(1, 0, 1)).normalized; // カメラから見た入力方向を取得 Vector3 direction = cameraForward * inputZ + PlayerCamera.transform.right * inputX; float delta = fixedUpdate ? Time.fixedDeltaTime : Time.deltaTime; if (mode != PlayState.GameMode.Pause) { bool input; float inputSpeed = Mathf.Sqrt((inputX * inputX) + (inputZ * inputZ)); // NavMeshの更新 if (mode == PlayState.GameMode.Rain) { navMeshFlag = true; specialMove = true; playerAgent.updatePosition = false; playerRigid.isKinematic = false; } else { // ナビメッシュの更新をかける if (navMeshFlag) { navMeshFlag = false; UpdateNavMesh(); } // アメフラシ起動またはジャンプの動作が終了したら座標を更新する if (specialMove && CliffFlag == false) { specialMove = false; playerAgent.Warp(transform.position); playerAgent.updatePosition = true; playerRigid.isKinematic = true; } } // 一方通行の崖を利用する際に実行 if (CliffFlag) { specialMove = true; playerAgent.updatePosition = false; input = false; } else { // 移動方向 Vector3 moveDirection = Vector3.zero; // 入力の最低許容値 float inputMin = 0.1f; input = (Mathf.Abs(inputX) > inputMin || Mathf.Abs(inputZ) > inputMin) && mode == PlayState.GameMode.Play && dontInput == false; if (input) { // 入力方向を向く処理 Quaternion rot = Quaternion.LookRotation(direction, Vector3.up); rot = Quaternion.Slerp(transform.rotation, rot, 7.5f * delta); transform.rotation = rot; // 水中かどうかをチェックし、加速度グラフに基づいた移動速度を計算 float speed = inWater ? playerWaterSpeed : playerSpeed; if (speedTime < maxSpeedTime) { speedTime += delta; } else { speedTime = maxSpeedTime; } // 地面にRayを飛ばす Ray ground = new Ray(new Vector3(transform.position.x, transform.position.y + playerCollider.center.y, transform.position.z), Vector3.down); float hitNomalY = 1.0f; if (Physics.Raycast(ground, out RaycastHit hit, rayLength, groundLayer)) { // 地面の傾斜を取得 hitNomalY = hit.normal.y; } // 斜め入力時の移動量を修正 moveDirection = direction.normalized; // 坂を移動する際の傾斜を考慮した移動量に修正 if (hitNomalY != 1.0f) { var nomal = hit.normal; Vector3 dir = moveDirection - Vector3.Dot(moveDirection, nomal) * nomal; moveDirection = dir.normalized; } // 移動量にスピード値を乗算 moveDirection *= speed * inputSpeed * curve.Evaluate(speedTime / maxSpeedTime); } else { speedTime = 0; } // プレイヤーを移動させる if (playerNav != null && playerAgent.updatePosition) { playerAgent.Move(moveDirection * delta); } // 水中フラグの設定 if (StageWater != null) { inWater = (transform.position.y + playerCollider.center.y) - (playerCollider.height * 0.25f) < StageWater.max; UnderWater = transform.position.y + playerCollider.center.y + playerCollider.height * 0.25f < StageWater.max; } else { inWater = false; UnderWater = false; } // AnimationEventの設定 if (animeEvent != null) { if (UnderWater) { animeEvent.PlayerStepMode = StepMode.UnderWater; } else if (inWater) { animeEvent.PlayerStepMode = StepMode.InWater; } else { animeEvent.PlayerStepMode = StepMode.Nomal; } animeEvent.PlayerPosition = transform.position; } } // アニメーション実行 if (playerAnimator != null) { playerAnimator.enabled = true; if (umbrellaAnimator != null) { umbrellaAnimator.enabled = true; } // 走るアニメーション playerAnimator.SetBool("Run", input); playerAnimator.SetFloat("Speed", inWater ? (inputSpeed * curve.Evaluate(speedTime / maxSpeedTime)) / (playerSpeed / playerWaterSpeed) : inputSpeed * curve.Evaluate(speedTime / maxSpeedTime)); // アメフラシを起動するアニメーション playerAnimator.SetBool("Switch", mode == PlayState.GameMode.Rain); // 崖から降りるアニメーション playerAnimator.SetBool("Jump", CliffFlag); // ゲームオーバー時のアニメーション playerAnimator.SetBool("GameOver", mode == PlayState.GameMode.GameOver); // クリア時のアニメーションを再生 if (mode == PlayState.GameMode.Clear) { if (RotateAnimation(transform.gameObject, cameraForward * -1, 360 * delta, true)) { playerAnimator.SetBool("Run", false); playerAnimator.SetBool("StageClear", true); } } } } else { // アニメーションの停止 if (playerAnimator != null) { // ポーズ中のみアニメーションを停止 playerAnimator.enabled = false; if (umbrellaAnimator != null) { umbrellaAnimator.enabled = false; } } } }
public void Warp(Vector3 position) { agent.Warp(position); }
private NPC initNPC() { GameObject npcObject = Instantiate(npcsToLoad[rnd.Next(npcsToLoad.Count)], PopulationList.transform); NavMeshAgent agent = npcObject.GetComponent <NavMeshAgent>(); NPC npc = npcObject.GetComponent <NPC>(); Transform house = TaskManager.instance.assignHouse(); Transform door = house.Find("Door").transform; NavMeshHit hit; if (NavMesh.SamplePosition(door.position, out hit, 20f, NavMesh.AllAreas)) { agent.Warp(hit.position); } else { Debug.Log("Failed to find starting position for NPC"); } npc.house = house; // Set NPC names if (npc.gameObject.name.Contains("Female")) { npc.name = string.Format("{0} {1}", femaleFirstNames[rnd.Next(femaleFirstNames.Count)], lastNames[rnd.Next(lastNames.Count)]); } else if (npc.gameObject.name.Contains("Male")) { npc.name = string.Format("{0} {1}", maleFirstNames[rnd.Next(maleFirstNames.Count)], lastNames[rnd.Next(lastNames.Count)]); } npc.initializeDay(TaskManager.instance.assignTasks()); npc.completedDay.AddListener(() => { npcsFinished++; if (npcsFinished == population) { uint tempImmune = 0; npcsFinished = 0; foreach (NPC n in npcList) { if (n.isDead) { population--; numDeaths++; Debug.Log("NPC " + npc.name + " dead. Total deaths: " + numDeaths); // Destroy(n.gameObject); } else { if (n.isImmune) { tempImmune++; } n.agent.enabled = true; } } numImmune = tempImmune; npcList.RemoveAll(n => n.isDead); Debug.Log("Day finished"); Debug.Log("Number of Immune at end of day: " + NPCManager.instance.numImmune); dayFinished.Invoke(); } }); return(npc); }
public void SetNavpos(Vector3 position) { m_navAgent.Warp(position); }
private IEnumerator <float> _FireballController() { // Infinite loop to keep this method working all the time while (true) { // Checks the current Nav Mesh layer of the player _currentNavMeshLayer = CheckCurrentNavMeshLayer(); // If we press the mouse button for moving if (Input.GetMouseButtonDown(0) && !_isTeleporting && !_gameManager.clickedOnFire && !inputDisabled) { // Get the Nav Mesh layer of where the player clicked int clickedNavMeshLayer = CheckClickedNavMeshLayer(_mousePosition); // Calculations for fireball cost. It's a sum because the cost is always negative float remainingFire = _playerController.playerCurrentFire + _playerController.fireballCost; // Don't let the player teleport to another mesh (or to somewhere weird like Australia) nor let him cast if out of power if (_currentNavMeshLayer == clickedNavMeshLayer && clickedNavMeshLayer != -1 && remainingFire >= 0) { // Disable movement and mouselook since animations will play EnablePlayerMovement(false); // Wait one frame yield return(Timing.WaitForOneFrame); // Stop any movement animations _animator.SetFloat("Speed", 0); // Wait one frame yield return(Timing.WaitForOneFrame); //Play the animation _animator.SetTrigger("Casting Fireball"); // Raise the teleporting flag! _isTeleporting = true; // Substract fire power from the player _playerController.SetFireValue(_playerController.fireballCost); // Initial particle effects SpawnInitialNova(); // Wait for initial animations to play yield return(Timing.WaitForSeconds(0.4f)); // Make player invisible _animator.SetBool("Character Visible", false); // Spawn a fireball!!! _fireball.SetActive(true); // Move the fireball towards the clicked point, this is done in Update _moveFireball = true; // Wait for the fireball to finish it's movement while (_continueCoroutine == false) { yield return(Timing.WaitForOneFrame); } // The fireball arrived, we stop moving and turn off the fireball _fireball.SetActive(false); // Reset the flag once we've continued _continueCoroutine = false; // Wait one frame yield return(Timing.WaitForOneFrame); // Warp to where the mouse was pointing _agent.Warp(_mousePosition); // Reset animation trigger _animator.ResetTrigger("Casting Fireball"); // Wait one frame yield return(Timing.WaitForOneFrame); // Make the player visible again _animator.SetBool("Character Visible", true); // Play the ending explosion SpawnMediumExplosion(); // Reenable movement EnablePlayerMovement(true); // Lower the teleporting flag! _isTeleporting = false; } else { if (remainingFire < 0) { // We display a message SetFloatingTextValue("I need fire..."); floatingTextObject.SetActive(true); yield return(Timing.WaitForSeconds(0.75f)); floatingTextObject.SetActive(false); } } } // Wait one frame, otherwise this will crash Unity! yield return(Timing.WaitForOneFrame); } }
private void Update() { if (Time.time < respawnTime) { return; } else if (!alive) // respawn { alive = true; health = startingHealth; if (team == Team.bookWorm) { nav.Warp(GameManager.BookWormsSpawnObject.transform.position); } if (team == Team.jocks) { nav.Warp(GameManager.JocksSpawnObject.transform.position); } if (team == Team.scienceGeek) { nav.Warp(GameManager.ScienceGeeksSpawnObject.transform.position); } idling = false; } if (!alive) { return; } if (!NPCAnimator.GetCurrentAnimatorStateInfo(0).IsName("Unarmed-Attack-R3")) { if (!NPCAnimator.GetCurrentAnimatorStateInfo(0).IsName("Unarmed-Death1")) { if (!NPCAnimator.GetCurrentAnimatorStateInfo(0).IsName("Unarmed-GetHit-F1")) { if (!idling) { nav.isStopped = false; NPCAnimator.SetBool("Moving", true); } } } } if (Time.time > nextShuffleTime) { VariableShuffle(); } if (Time.time < fleeUntilTime) { return; } nearestEnemy = FindNearestEnemy(); if (!Ammo.Any()) { idling = false; nearestVendor = FindNearestVendor(null); nav.SetDestination(nearestVendor.position); if (nearestEnemy != null && enemyDistance < fleeRadius) { switch (fleePersonality) { case FleePersonality.Direct: // run away from enemy nav.SetDestination((transform.position - nearestEnemy.position) * fleeMagnitude); //fleeUntilTime = Time.time + Random.Range(fleeTimerMin, fleeTimerMax); fleeUntilTime = Time.time + shortFleeTimer; break; case FleePersonality.ToVendor: // find nearest vendor nav.SetDestination(FindNearestVendor(nearestVendor).position); fleeUntilTime = Time.time + Random.Range(fleeTimerMin, fleeTimerMax); break; case FleePersonality.ToBase: // flee to base nav.SetDestination(GameManager.JocksSpawnObject.transform.position); fleeUntilTime = Time.time + Random.Range(fleeTimerMin, fleeTimerMax); break; } } } else if (nearestEnemy != null) // attack mode { idling = false; nav.SetDestination(nearestEnemy.position); if (enemyDistance <= attackRadius) // enemy within range { if (Time.time > nextAttackTime) // shooting cooldown expired { if (Ammo.Any()) // has ammo { nav.isStopped = true; NPCAnimator.SetTrigger("Attack"); nextAttackTime = Time.time + attackCooldown; } } } else { GoToCap(); } } else { GoToCap(); } }
private void OnNavMeshStateUpdateClientRpc(Vector3 destination, Vector3 velocity, Vector3 position, ClientRpcParams rpcParams = default) { m_Agent.Warp(WarpOnDestinationChange ? position : Vector3.Lerp(transform.position, position, DriftCorrectionPercentage)); m_Agent.SetDestination(destination); m_Agent.velocity = velocity; }
void Start() { agent.Warp(gameObject.transform.position);// Put the agent iun the selected position of the NavMesh }