public void Push(Vector3 direction) { _agent.Move(direction); }
public void Move(Vector3 movementOffset) { movementOffset = Vector3.ClampMagnitude(movementOffset, MoveSpeed); meshAgent.Move(movementOffset); RotateTowardsMovementDirection(movementOffset); }
// 寻路移动 void MoveTo() { float speed = m_movSpeed * Time.deltaTime; m_agent.Move(m_transform.TransformDirection((new Vector3(0, 0, speed)))); }
// Update is called once per frame void Update() { nav.Move(Vector3.right * Time.deltaTime); }
private void FixedUpdate() { float speedfaktor = 5 * GetMovementRateModifier(); if (!GetOverrideMovement()) { //left stick targetVel = new Vector3(Input.GetAxisRaw("Horizontal_" + PlayerID), 0, Input.GetAxisRaw("Vertical_" + PlayerID)); } else { targetVel = OverrideMovementVec; } if (!GetOverrideRotation()) { //right stick targetDir = new Vector3(Input.GetAxisRaw("Horizontal2_" + PlayerID), 0, -Input.GetAxisRaw("Vertical2_" + PlayerID)); } else { targetDir = OverrideRotationVec; } if (Vector3.Magnitude(targetDir) <= 0.3f) { targetDir = targetVel; } targetVel = targetVel * speedfaktor * Time.deltaTime; // Rotate towards Velocity Direction: if (targetDir.sqrMagnitude > 0) { transform.rotation = Quaternion.Slerp(gameObject.transform.rotation, Quaternion.LookRotation(targetDir), Time.deltaTime * RotationSpeed); } //PhysCont.SetVelRot(targetVel, targetDir); NavAgent.Move(targetVel); if (!IsWalking && (GetOverrideMovement() || (Input.GetAxisRaw("Horizontal_" + PlayerID) >= 0.05f || Input.GetAxisRaw("Vertical_" + PlayerID) >= 0.05f || Input.GetAxisRaw("Horizontal_" + PlayerID) <= -0.05f || Input.GetAxisRaw("Vertical_" + PlayerID) <= -0.05f))) { IsWalking = true; StartBodyAnimation(Anim_StartWalking); } else if (IsWalking) { if (!GetOverrideMovement() && (Input.GetAxisRaw("Horizontal_" + PlayerID) < 0.05f && Input.GetAxisRaw("Vertical_" + PlayerID) < 0.05f && Input.GetAxisRaw("Horizontal_" + PlayerID) > -0.05f && Input.GetAxisRaw("Vertical_" + PlayerID) > -0.05f)) { IsWalking = false; StartBodyAnimation(Anim_EndWalking); } else { StartBodyAnimation(speedfaktor / 10); } } }
void MoveTo() { float speed = moveSpeed * Time.deltaTime; agent.Move(transform.TransformDirection(new Vector3(0, 0, speed))); }
/// <summary> /// /// </summary> /// <param name="opv"></param> public void GoToPosition(Vector3 opv) { agent.Move(opv); }
public void SetTarget(Vector3 targetPosition) => _navMeshAgent.Move((targetPosition - transform.position).normalized * Time.deltaTime * _moveSpeed);
private void MoveWithAgent() { agent.Move(transform.TransformDirection(velocity) * agentSpeedMult * Time.deltaTime); transform.Rotate(angularVelocity * agentRotMult * agent.angularSpeed * Time.deltaTime, Space.Self); }
public void MoveForward(float deltaTime) { agent.Move(transform.forward * data.Speed * deltaTime); }
// Update is called once per frame void Update() { if (anim.GetCurrentAnimatorStateInfo(0).IsName("FlyBack") && anim.GetCurrentAnimatorStateInfo(0).normalizedTime < 0.8f) { return; } if (isPerformingLongRangeAttack == true && !anim.GetCurrentAnimatorStateInfo(0).IsName("Walk")) { anim.ResetTrigger("Walk"); } if (isMonsterHit == true) { if (timer < 3f && (!anim.GetCurrentAnimatorStateInfo(0).IsName("StandUp"))) { timer += Time.deltaTime; } else { timer = 0; isMonsterHit = false; } } else if (isMonsterHit == false && playerHurt == false) { haltCombo = false; } this.transform.position = new Vector3(this.transform.position.x, 0, this.transform.position.z); distMagnitude = dist.magnitude; dist = player.transform.position - this.transform.position; dist.y = 0; if (isMonsterHit == true) { anim.ResetTrigger("Walk"); } else if (dist.magnitude < RangeFromPlayer && isMonsterHit == false) { Quaternion transRot = Quaternion.LookRotation(new Vector3(player.transform.position.x - this.transform.position.x, 0, player.transform.position.z - this.transform.position.z), transform.up); this.transform.rotation = Quaternion.Slerp(transRot, this.transform.rotation, 0.7f); if (dist.magnitude > 11f) { if (LongRange == true) { if (isPerformingLongRangeAttack == false) {//anim.SetTrigger("GroundSmash"); SelectLongRangeAttack(); if (LongRangeInt == 0) { if (!anim.GetCurrentAnimatorStateInfo(0).IsName("Slash")) { anim.SetTrigger("GroundSmash"); } } else if (LongRangeInt == 1) { if (!anim.GetCurrentAnimatorStateInfo(0).IsName("GroundSmash")) { anim.SetTrigger("Slash"); } StartCoroutine(SetSlashPerformingLongeFalse()); } } } else //charCont.Move(dist.normalized*10 * Time.deltaTime); { if (!(anim.GetCurrentAnimatorStateInfo(0).IsName("FlyBack")) && !(anim.GetCurrentAnimatorStateInfo(0).IsName("StandUp"))) { if (isPerformingLongRangeAttack == true) { anim.SetTrigger("Idle"); } else { anim.SetTrigger("Walk"); nav.Move(dist.normalized * 10 * Time.deltaTime); } } } } else { if (!(anim.GetCurrentAnimatorStateInfo(0).normalizedTime < 1)) { comboInAction = false; } // Debug.Log("Resetting walk"); SelectCombo(); } } else if (dist.magnitude >= RangeFromPlayer) { if (!(anim.GetCurrentAnimatorStateInfo(0).IsName("IdleMonster"))) { anim.SetTrigger("Idle"); } else if (playerHurt == true) { anim.SetTrigger("Idle"); } } if (!charCont.isGrounded) { charCont.Move(new Vector3(0, -4 * Time.deltaTime, 0)); } this.gameObject.transform.position = new Vector3(this.transform.position.x, 0, this.transform.position.z); }
public void Move(Vector3 direction) { this.moveDirection = direction; agent.Move(moveDirection); }
// Update is called once per frame void Update() { if (Input.GetKey(KeyCode.LeftArrow)) //左 { agent.Move(Vector3.left * speed.z); } else if (Input.GetKey(KeyCode.UpArrow)) { agent.Move(Vector3.back * speed.z); } else if (Input.GetKey(KeyCode.DownArrow)) { agent.Move(Vector3.forward * speed.z); } else if (Input.GetKey(KeyCode.RightArrow)) //下 { agent.Move(Vector3.right * speed.z); } else if (Input.GetKey(KeyCode.C)) { } Vector3?dest = null; //传送过程中不能操作 if ((moveState & MoveState.Teleport) == MoveState.NONE) { if (Input.GetKey(KeyCode.D)) //右 { moveDir = -1; //右边 interTrans.eulerAngles = new Vector3(0, 270, 0); int idx = -1; if ((idx = CheckTrigger(false, TeleportType.DownRight)) >= 0) //传送到其他地方 { moveState |= MoveState.Teleport; moveState &= ~MoveState.Normal; agent.updatePosition = false; lastTrigger = teleports[idx]; teleportStartPos = transform.position; teleportDest = lastTrigger.worldDestPos; teleportDest.x += modelSize.x / 2 * moveDir; totalTeleportTime = Mathf.Sqrt(Mathf.Abs(teleportDest.y - transform.position.y) * 2 / gravity); //总时间 curTeleportTime = 0f; teleportVel = new Vector3(moveDir * agent.speed, 0f, 0f); // (teleportDest - teleportStartPos + 0.5f * new Vector3(0f, gravity, 0f) * teleportTime * teleportTime) / teleportTime; } else { moveState |= MoveState.Normal; dest = agent.transform.position + Vector3.left * speed.z; // } } else if (Input.GetKey(KeyCode.W)) { moveState |= MoveState.Normal; dest = agent.transform.position + Vector3.back * speed.z; } else if (Input.GetKey(KeyCode.S)) { moveState |= MoveState.Normal; dest = agent.transform.position + Vector3.forward * speed.z; } else if (Input.GetKey(KeyCode.A)) //左 { interTrans.eulerAngles = new Vector3(0, 90, 0); moveDir = 1; int idx = -1; if ((idx = CheckTrigger(false, TeleportType.DownLeft)) >= 0) //传送到其他地方 { moveState |= MoveState.Teleport; moveState &= ~MoveState.Normal; agent.updatePosition = false; lastTrigger = teleports[idx]; teleportStartPos = transform.position; teleportDest = lastTrigger.worldDestPos; teleportDest.x += modelSize.x / 2 * moveDir; totalTeleportTime = Mathf.Sqrt(Mathf.Abs(teleportDest.y - transform.position.y) * 2 / gravity); //总时间 curTeleportTime = 0f; teleportVel = new Vector3(moveDir * agent.speed, 0f, 0f); } else { moveState |= MoveState.Normal; dest = agent.transform.position + Vector3.right * speed.z; } } else //没有一般移动 { moveState &= ~MoveState.Normal; } //可以同时按下方向键和空格键 if (Input.GetKey(KeyCode.Space)) //跳跃 { if (jumpTime == 0f) { jumpTime = 0f; } moveState |= MoveState.Jump; int idx = -1; if ((idx = CheckTrigger(false, moveDir == -1 ? TeleportType.JumpRight : TeleportType.JumpLeft)) >= 0) //传送到其他地方 { moveState |= MoveState.Teleport; moveState &= ~MoveState.Normal; agent.updatePosition = false; lastTrigger = teleports[idx]; teleportStartPos = transform.position; teleportDest = lastTrigger.worldDestPos; float y = 0f; if (lastTrigger.type == TeleportType.UpLeft || lastTrigger.type == TeleportType.UpRight) //向上跳需要更大的加速度 { y = teleportDest.y - transform.position.y; // + 1f; teleportVel = new Vector3(agent.speed * moveDir, gravity * Mathf.Sqrt(2 * y / gravity), 0f); totalTeleportTime = Mathf.Sqrt(2 * y / gravity); // + Mathf.Sqrt(2/gravity); } else { teleportVel = new Vector3(agent.speed * moveDir, jumpVel, 0f); y = transform.position.y - teleportDest.y; totalTeleportTime = jumpVel / gravity + Mathf.Sqrt(2 * (0.5f * jumpVel * jumpVel / gravity + transform.position.y - teleportDest.y) / gravity); } curTeleportTime = 0f; } } } if ((moveState & MoveState.Teleport) != MoveState.NONE) //传送状态 { if (curTeleportTime < totalTeleportTime) { curTeleportTime += Time.deltaTime; transform.position = CalcTeleportPos(curTeleportTime); interTrans.localPosition = Vector3.zero; } else { var tmp = transform.position; tmp.y = teleportDest.y; agent.Warp(tmp); agent.updatePosition = true; moveState &= ~MoveState.Teleport; moveState &= ~MoveState.Jump; totalTeleportTime = 0f; curTeleportTime = -1f; lastTrigger = null; animContrller.SetInteger("aniState", (int)PlayerAnimationNames.IDLE1); } } else { if ((moveState & MoveState.Normal) != MoveState.NONE) //一般的移动 { if (dest != null) { agent.SetDestination(dest.Value); } } else { agent.Warp(transform.position); //停到当前的位置 } if ((moveState & MoveState.Jump) != MoveState.NONE) //跳跃状态 { var y = jumpVel * jumpTime - 0.5f * gravity * jumpTime * jumpTime; jumpTime += Time.deltaTime; if (jumpTime > 0.1f && y < 0f) { moveState &= ~MoveState.Jump; y = 0f; jumpTime = 0f; } interTrans.localPosition = new Vector3(0, y, 0); } } //动作的处理部分 if ((moveState & MoveState.Jump) != MoveState.NONE) { animContrller.SetInteger("aniState", (int)PlayerAnimationNames.JUMP); } else if ((moveState & MoveState.Normal) != MoveState.NONE) { animContrller.SetInteger("aniState", (int)PlayerAnimationNames.RUN); } else { animContrller.SetInteger("aniState", (int)PlayerAnimationNames.IDLE1); } if (Input.mouseScrollDelta.y != 0f) { scrollDelta += Input.mouseScrollDelta.y; z += Input.mouseScrollDelta.y; z = Mathf.Max(z, minZ); z = Mathf.Min(z, maxZ); } var temp = character.position; temp.z = z; cam.transform.position = temp; }
public void Move(Vector3 direction) { navMeshAgent.Move(direction * navMeshAgent.speed * Time.deltaTime); }
public void SetPos(Vector3 vec) { // transform.position = vec; _navAgent.Move(vec - transform.position); _navAgent.isStopped = true; }
private void Update() { currentTimer += 1 * Time.deltaTime; if (enemyChase.shipTarget == null && health.isDead == false) { if (currentTimer >= maxTimer) { //m_Agent.destination = m_HitInfo.point; m_Path = new NavMeshPath(); enemAgent.CalculatePath(Wander(), m_Path); pathIter = 1; enemAgent.isStopped = false; currentTimer = 0; } } if (m_Path.corners == null || m_Path.corners.Length == 0) { return; } if (pathIter >= m_Path.corners.Length) { if (!health.isDead) { destination = new Vector3(float.PositiveInfinity, float.PositiveInfinity, float.PositiveInfinity); } enemAgent.isStopped = true; return; } else { destination = m_Path.corners[pathIter]; } if (destination.x < float.PositiveInfinity) { Vector3 direction = destination - AgentPosition; var newDir = Vector3.RotateTowards(transform.forward, direction, 50 * Time.deltaTime, 0.0f); var newRot = Quaternion.LookRotation(newDir); transform.rotation = Quaternion.Slerp(transform.rotation, newRot, Time.deltaTime * SPEED); float distance = Vector3.Distance(AgentPosition, destination); if (distance > enemAgent.radius + 0.1) { Vector3 movement = transform.forward * Time.deltaTime * SPEED; //if not dead if (!health.isDead) { enemAgent.Move(movement); } } else { ++pathIter; if (pathIter >= m_Path.corners.Length) { //here!! //destination = new Vector3(float.PositiveInfinity, float.PositiveInfinity, float.PositiveInfinity); enemAgent.isStopped = true; } } } }
void Patrol() { lazer = false; agent.speed = patrolSpeed; path = new NavMeshPath(); if (gameObject.CompareTag("FloatingEyebot")) { agent.stoppingDistance = 1; } //path = new NavMeshPath(); //agent.CalculatePath(waypoints[waypointInd].transform.position, path); //chaseSpeed = 3; //agent.speed = chaseSpeed; //agent.isStopped = true; //agent.SetPath(path); if (Vector3.Distance(transform.position, waypoints[waypointInd].transform.position) > 2) { agent.SetDestination(waypoints[waypointInd].transform.position); if (pathpending) { agent.isStopped = false; if (Vector3.Distance(playa.position, transform.position) <= 150) { agent.Move(agent.desiredVelocity * Time.deltaTime); } } if (!pathpending) { agent.isStopped = false; if (Vector3.Distance(playa.position, transform.position) <= 150) { agent.Move(agent.desiredVelocity * Time.deltaTime); } } //agent.CalculatePath(waypoints[waypointInd].transform.position, path); //agent.SetPath(path); agent.SetDestination(waypoints[waypointInd].transform.position); if (Vector3.Distance(playa.position, transform.position) <= 150) { agent.Move(agent.desiredVelocity * Time.deltaTime); } //character.Move(agent.desiredVelocity, false, false); } else if (Vector3.Distance(transform.position, waypoints[waypointInd].transform.position) <= 2) { //agent.destination = (waypoints[waypointInd+1].transform.position); //agent.Move(agent.desiredVelocity * Time.deltaTime); //character.Move(Vector3.zero, false, false); if (!randomize) { waypointInd = waypointInd += 1; if (waypointInd >= waypoints.Length) { waypointInd = 0; } } if (randomize) { waypointInd = Random.Range(0, waypoints.Length); } //Patrol(); agent.SetDestination(waypoints[waypointInd].transform.position); //agent.CalculatePath(waypoints[waypointInd].transform.position, path); //agent.SetPath(path); agent.Move(agent.desiredVelocity * Time.deltaTime); //character.Move(agent.desiredVelocity, false, false); } else { //character.Move(Vector3.zero, false, false); //agent.SetDestination(waypoints[waypointInd].transform.position); //character.Move(agent.desiredVelocity, false, false); } }
void NavMeshAgentMove(float horizontal, float vertical) { _agent.Move(transform.forward * vertical * _speed * Time.deltaTime); _rigidbody.AddTorque(new Vector3(0, horizontal * 0.5f * _speed, 0)); }
//Input Controls void Control() { //Para evitar que se desajuste la animación con los cambios de cámara de las cinemáticas. if (isShooting) { anim.enabled = false; } else { anim.enabled = true; } //Si el Manager nos permite movernos if (MazzManager.mm.canMove || alwaysMove) { //Cosas de camara xRotCounter += Input.GetAxis("Mouse X") * xMoveThreshold * Time.deltaTime; yRotCounter += Input.GetAxis("Mouse Y") * yMoveThreshold * Time.deltaTime; yRotCounter = Mathf.Clamp(yRotCounter, yMinLimit, yMaxLimit); //xRotCounter = xRotCounter % 360;//Optional playerCam.localEulerAngles = new Vector3(-yRotCounter, xRotCounter, 0); if (Input.GetAxis("Vertical") != 0 || Input.GetAxis("Horizontal") != 0) { anim.SetBool("Walking", true); if (!audioWalking.isPlaying) { audioWalking.Play(); } } else { anim.SetBool("Walking", false); audioWalking.Stop(); } if (hidePantufla) { weapon.GetComponent <BoxCollider>().enabled = false; weapon.transform.GetChild(0).gameObject.SetActive(false); //weapon.SetActive(false); } else { //weapon.GetComponent<BoxCollider>().enabled = true; weapon.transform.GetChild(0).gameObject.SetActive(true); //weapon.SetActive(true); } navMeshAgent.Move(playerCam.forward * Input.GetAxis("Vertical") * Time.deltaTime * speed); navMeshAgent.Move(playerCam.right * Input.GetAxis("Horizontal") * Time.deltaTime * speed); if (Input.GetButtonDown("Fire2") && !isShooting && !attacking) { Instantiate(prefab, shootPoint.transform.position, shootPoint.transform.rotation); isShooting = true; } if (Input.GetButtonDown("Fire1") && !hidePantufla) { weapon.GetComponent <BoxCollider>().enabled = true; attacking = true; anim.SetTrigger("Attacking"); //Ataque principal audioHit.Play(); Invoke("DisableWeapon", 0.5f); } } }
public void Move() { agent.Move(transform.forward * Time.deltaTime * speed); }
// Update is called once per frame void Update() { // BOAT TARGETING // Do I have a boat as target (and not on an alternative path) ? if (boat.target != null && timeUntilResettingCourse < 0 && useAINav) { // check range float dist = Vector3.Distance(transform.position, boat.target.transform.position); if (dist > (boat.firing ? FIRING_DIST_GO_NEAR_AGAIN : FIRING_DIST)) { // go nearer agent.destination = boat.target.transform.position; // stop firing boat.firing = false; } else { // near enough boat.firing = true; // go 90° to fire NavMeshHit actualPoint; NavMesh.SamplePosition( transform.position + (Quaternion.AngleAxis(90, Vector3.up) * (boat.target.transform.position - transform.position)).normalized * agent.speed, out actualPoint, 2, -1); agent.destination = actualPoint.position; } } // RIGHT CLICK TO MOVE if (Input.GetMouseButtonDown(1) && !EventSystem.current.IsPointerOverGameObject()) { RaycastHit hit; if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 1000)) { // WAYPOINTS if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.LeftControl)) { // add a new waypoint Debug.Log("New waypoint"); wayPoints.Add(hit.point); wayPointMarkers.Add(GameObject.Instantiate(markersPrefab, hit.point, Quaternion.identity)); if (wayPoints.Count == 1) // first one ? { agent.destination = hit.point; } } else { Debug.Log("Clear waypoints"); // clear all wayPoints.Clear(); wayPointMarkers.ForEach(o => GameObject.Destroy(o)); wayPointMarkers.Clear(); // add a new waypoint wayPoints.Add(hit.point); wayPointMarkers.Add(GameObject.Instantiate(markersPrefab, hit.point, Quaternion.identity)); agent.destination = hit.point; } } } // Check to see if we're near of a waypoint and there remaining waypoints after that if (agent.remainingDistance < MIN_REMAINING_DIST && wayPoints.Count > 1) { // remove current one wayPoints.RemoveAt(0); GameObject.Destroy(wayPointMarkers[0]); wayPointMarkers.RemoveAt(0); // next! agent.destination = wayPoints[0]; } // update agent speed depending on wind agent.speed = Common.baseBoatSpeed * WindFactor(); // ZIGZAG WHEN FACING WIND // check if we're on alternate course if (timeUntilResettingCourse > 0) { timeUntilResettingCourse -= Time.deltaTime; // time to get back on original course if (timeUntilResettingCourse < 0) { agent.destination = storedDestination; } else { // go in the newDir direction // try to find a point on the navmesh NavMeshHit actualPoint; NavMesh.SamplePosition(this.transform.position + newDir, out actualPoint, 5, -1); agent.destination = actualPoint.position; debugPillar.transform.position = actualPoint.position; } } // TURNING AND WIND if (agent.hasPath) { // get angle between the next straight line and direction float angleToTurn = Vector3.SignedAngle(agent.steeringTarget - this.transform.position, this.transform.forward, Vector3.up); if (Mathf.Abs(angleToTurn) > 60 && agent.velocity.magnitude < 1) { agent.isStopped = true; this.transform.Rotate(0, agent.angularSpeed * Time.deltaTime * -Mathf.Sign(angleToTurn), 0); agent.Move(this.transform.forward * (agent.speed * Time.deltaTime / 5)); } else { agent.isStopped = false; // are we already on alternate course AND using AI to avoid facing the wind ? if (timeUntilResettingCourse < 0 && useAINav) { // NO, then check if the boat is facing the wind int dir = 180 - (int)Vector3.SignedAngle(agent.steeringTarget - this.transform.position, Vector3.back, Vector3.up); int angleDiff = Mathf.Abs(uiManager.Wind - dir) % 360; if (angleDiff > 160 && angleDiff < 200) // lest than 20° from facing the wind // change goal for 2sec // first find new angle { int newAngle = angleDiff < 180 ? uiManager.Wind - 140 : uiManager.Wind + 140; // new angle diff is 140° // get new direction newDir = Quaternion.AngleAxis(newAngle, Vector3.up) * Vector3.forward * Common.baseBoatSpeed; storedDestination = agent.destination; timeUntilResettingCourse = 1; } } } } }
void Update() { if (leftController.GetButton((Valve.VR.EVRButtonId)runButton) || rightController.GetButton((Valve.VR.EVRButtonId)runButton) && !isToggle) { zVelLeft = vrRig.s_head.transform.InverseTransformDirection(leftController.getDeviceVelocity()).z; zVelRight = vrRig.s_head.transform.InverseTransformDirection(rightController.getDeviceVelocity()).z; xVelLeft = vrRig.s_head.transform.InverseTransformDirection(leftController.getDeviceVelocity()).x; xVelRight = vrRig.s_head.transform.InverseTransformDirection(rightController.getDeviceVelocity()).x; if (swingingArmBack && motionType != eMotionType.BREAST_STROKE) { float posX = (leftController.getDeviceVelocity().x < 0) ? leftController.getDeviceVelocity().x * -1 : leftController.getDeviceVelocity().x; float posY = (leftController.getDeviceVelocity().y < 0) ? leftController.getDeviceVelocity().y * -1 : leftController.getDeviceVelocity().y; float posZ = (leftController.getDeviceVelocity().z < 0) ? leftController.getDeviceVelocity().z * -1 : leftController.getDeviceVelocity().z; swingForce = Mathf.Max(posX, posY, posZ) * swingForceMultiplier; agent.Move(transform.root.GetComponent <VRLocomotionRig>().s_head.transform.forward *moveSpeed *swingForce *Time.deltaTime); } else if (swingingArmBack && motionType == eMotionType.BREAST_STROKE) { switch (swimSettings) { case eSwimSettings.FREE: { agent.enabled = false; float posX = (leftController.getDeviceVelocity().x < 0) ? leftController.getDeviceVelocity().x * -1 : leftController.getDeviceVelocity().x; float posY = (leftController.getDeviceVelocity().y < 0) ? leftController.getDeviceVelocity().y * -1 : leftController.getDeviceVelocity().y; float posZ = (leftController.getDeviceVelocity().z < 0) ? leftController.getDeviceVelocity().z * -1 : leftController.getDeviceVelocity().z; transform.root.position += transform.forward / (moveSpeed * 12) * (Mathf.Max(posX, posY, posZ) * 4); break; } case eSwimSettings.LOCKED_TO_NAV_MESH: agent.Move(transform.root.GetComponent <VRLocomotionRig>().s_head.transform.forward *Time.deltaTime *moveSpeed); break; } } switch (motionType) { case eMotionType.ARM_SWING: UpdateArmSwing(); break; case eMotionType.SKIING: UpdateSkiing(); break; case eMotionType.BREAST_STROKE: UpdateBreastStroke(); break; default: Debug.LogWarning("Somehow you have no motion type set??"); break; } } else if (leftController.GetButtonDown((Valve.VR.EVRButtonId)runButton) || rightController.GetButtonDown((Valve.VR.EVRButtonId)runButton) && isToggle) { toggleOn = !toggleOn; } if (isToggle) { if (toggleOn) { if (swingingArmBack && motionType != eMotionType.BREAST_STROKE) { agent.Move(transform.root.GetComponent <VRLocomotionRig>().s_head.transform.forward *Time.deltaTime *moveSpeed); } else if (swingingArmBack && motionType == eMotionType.BREAST_STROKE) { switch (swimSettings) { case eSwimSettings.FREE: { agent.enabled = false; transform.root.position += transform.forward / (moveSpeed * 12); break; } case eSwimSettings.LOCKED_TO_NAV_MESH: agent.Move(transform.root.GetComponent <VRLocomotionRig>().s_head.transform.forward *Time.deltaTime *moveSpeed); break; } switch (motionType) { case eMotionType.ARM_SWING: UpdateArmSwing(); break; case eMotionType.SKIING: UpdateSkiing(); break; case eMotionType.BREAST_STROKE: UpdateBreastStroke(); break; default: Debug.LogWarning("Somehow you have no motion type set??"); break; } } } else { agent.velocity = Vector3.zero; #if UNITY_5_6 agent.isStopped = true; #else agent.Stop(); #endif } } }
// Called every frame void Update() { // Tell other clients where this player is in the world (and their rotation) if (!photonView.isMine) { transform.position = Vector3.Lerp(transform.position, trueLoc, Time.deltaTime * 5); transform.rotation = Quaternion.Lerp(transform.rotation, trueRot, Time.deltaTime * 5); } // Move this player? else { // Get current 3D mouse position Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; // Set the movement speed navMeshAgent.speed = (champion.movementSpeed / 120f); if (Input.GetButton("Fire2") && !playerChampion.IsDead) { // Are we attacking an enemy? if (Physics.Raycast(ray, out hit, 100, LayerMask.GetMask("Targetable"))) { Targetable targetable = hit.transform.GetComponent <Targetable>(); // Is the enemy actually an enemy (on the other team)? if (targetable == null || (targetable != null && targetable.allowTargetingBy == photonView.owner.GetTeam())) { defaultAttack.target = hit.transform.gameObject; } } // Are we trying to move on the ground? else if (Physics.Raycast(ray, out hit, 100, LayerMask.GetMask("Floor"))) { // Are we in the top-down camera mode? if (mapProperties.display == PlayerCamera.CameraDisplays.TopDown) { defaultAttack.target = null; navMeshAgent.destination = hit.point; navMeshAgent.isStopped = false; } } } // Support for third-person camera mode using WASD instead of right-click if (mapProperties.display == PlayerCamera.CameraDisplays.ThirdPerson) { if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.S)) { playerAnimator.PlayAnimation("Walking"); } else { playerAnimator.PlayAnimation("Idle"); } if (Input.GetKey(KeyCode.W)) { navMeshAgent.Move(transform.forward / 18f); } if (Input.GetKey(KeyCode.A)) { transform.Rotate(Vector3.down * 3f); } if (Input.GetKey(KeyCode.S)) { navMeshAgent.Move(-transform.forward / 18f); } if (Input.GetKey(KeyCode.D)) { transform.Rotate(Vector3.up * 3f); } } // Stop moving if we have reached the destination or we are dead if (navMeshAgent.remainingDistance <= 0.2f || playerChampion.IsDead) { if (!navMeshAgent.isStopped) { playerAnimator.PlayAnimation("Idle"); } navMeshAgent.velocity = Vector3.zero; navMeshAgent.isStopped = true; } // Update the animation if all else fails if (!navMeshAgent.isStopped && playerAnimator.CurrentAnimation != "Walking") { playerAnimator.PlayAnimation("Walking"); } // Clear the target of our default attack when we die if (playerChampion.IsDead) { defaultAttack.target = null; } // Update the animation to walking if all else fails (volume 2) if (!navMeshAgent.isStopped) { if (onPlayerMove != null) { onPlayerMove(); } } } }
void LateUpdate() { if (!doRootMotion) { return; } float nextAnimTime = (playingAnimState.time + (Time.deltaTime * playingAnimState.speed)); // 다음 프레임에 애니메이션이 끝나는지 체크하기 위함. // 애니메이션 길이를 1이라고 봤을때, 0.9999라면, 다음 프레임은 내부적으로만 처리되기 때문에, // 정확한 위치 값 적용을 위해서 마지막도 계산필요. if (nextAnimTime >= playingAnimLength || !playingAnimState.enabled) { End(); return; } Vector3 newPos = playingCurve.GetOffset(playingAnimState.time); Vector3 deltaPos = newPos - prevFramePos; if (GameDefine.skillPushTest) { //if(mover.gameObject.GetComponent<Unit>().UnitType == UnitType.Unit || mover.gameObject.GetComponent<Unit>().UnitType == UnitType.Boss) if (!_ignoreEnemy) { Vector3 nextRealPos = mover.position + (Vector3.Dot(deltaPos, Vector3.forward) * mover.transform.forward); Vector3 dir = (nextRealPos - mover.position).normalized; //Debug.DrawRay(mover.position, dir, Color.red, 0.5f); RaycastHit hit; LayerMask mask = 1 << LayerMask.NameToLayer("Unit"); if (Physics.Raycast(mover.position, dir, out hit, 1f, mask)) //if (Physics.Raycast(mover.position, dir, out hit, 0.5f)) { //Debug.Log(hit); doRootMotion = false; return; } } } // 프레임당 이동값을 더해준다. if (null != moverAgent && moverAgent.enabled) { moverAgent.Move((Vector3.Dot(deltaPos, Vector3.forward) * mover.transform.forward)); } else { mover.transform.localPosition += (Vector3.Dot(deltaPos, Vector3.forward) * mover.transform.forward); } // 현재 로컬 위치를 저장해둔다. prevFramePos = newPos; // 로컬 위치 초기화 // TODO : die애니메이션의 x, z값 변동이 커서 눈에 띄어서 일단 주석. //animatedRoot.localPosition = new Vector3( 0, animatedRoot.localPosition.y, 0 ); }
public void IdleMovement() { if (idleDurration > 0) { Vector3 dir; idleDurration -= Time.deltaTime; if (idlestate == 1) { SwitchState(EnemyState.idle); } else if (idlestate == 2) { nav.updateRotation = true; dir = Vector3.forward; var lookPos = dir; var rotation = Quaternion.LookRotation(lookPos); SwitchState(EnemyState.walk); lookPos.y = 0; transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping); nav.Move(dir * (Speed * Time.deltaTime)); } else if (idlestate == 3) { nav.updateRotation = true; dir = Vector3.back; var lookPos = dir; var rotation = Quaternion.LookRotation(lookPos); SwitchState(EnemyState.walk); lookPos.y = 0; transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping); nav.Move(dir * (Speed * Time.deltaTime)); } else if (idlestate == 4) { nav.updateRotation = true; dir = Vector3.left; var lookPos = dir; var rotation = Quaternion.LookRotation(lookPos); SwitchState(EnemyState.walk); lookPos.y = 0; transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping); nav.Move(dir * (Speed * Time.deltaTime)); } else if (idlestate == 5) { nav.updateRotation = true; dir = Vector3.right; var lookPos = dir; var rotation = Quaternion.LookRotation(lookPos); SwitchState(EnemyState.walk); lookPos.y = 0; transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping); nav.Move(dir * (Speed * Time.deltaTime)); } } else if (idleDurration < 0) { idlestate = Random.Range(1, 6); idleDurration = Random.Range(1, 10); Invoke("IdleMovement", 0.1f); } }
void Update() { #if (UNITY_EDITOR) #region Lerp Stuff /* * Lerp test, this f*****g bullshit works, somehow * if(teste) * { * x = Mathf.Lerp(-1, 1, y); * y += 0.1f * Time.deltaTime; * * if (x >= 1) * { * y = 0; * teste = false; * } * } * else * { * x = Mathf.Lerp(1, -1, y); * y += 0.1f * Time.deltaTime; * * if (x <= -1) * { * y = 0; * teste = true; * } * } * Debug.Log(x + " , " + teste + " , " + y); */ #endregion if (indo) { hoi.Move(new Vector3(lateralMoveVel, 0, 0) * Time.deltaTime); } else { hoi.Move(new Vector3(lateralMoveVel * -1, 0, 0) * Time.deltaTime); } #endif if (Vector3.Distance(this.transform.position, player.transform.position) <= detectionDistance) { hoi.SetDestination(player.transform.position); following = true; } if (following) { if (Vector3.Distance(this.transform.position, player.transform.position) <= minDistance) { Ray t = new Ray(this.transform.position, (player.transform.position - this.transform.position)); RaycastHit you; Debug.DrawRay(this.transform.position, (player.transform.position - this.transform.position), Color.green); Physics.Raycast(t, out you); if (you.transform.gameObject.CompareTag("Player")) { Debug.Log("Attacking"); hoi.isStopped = true; } else { Debug.Log("Finding Angle"); hoi.isStopped = false; } } else { //follow player hoi.isStopped = false; } } }
/// <summary> /// Apply relative movement to current position. /// If the agent has a path it will be adjusted. /// </summary> /// <param name="offset">The relative movement vector.</param> public void Move(Vector3 offset) { NavMeshAgent.Move(offset); }
/* * Input: * DropPile - Space * Bark - E * Kill - Q * * Movement - WASD / ArrowKeys */ void Update() { if (control) { if (tutorialState > -1) { if (Time.time - lastTutorialTime > 10) { tutorialState = -1; playerText.text = ""; } if (tutorialState == 0) { tutorialState = 1; if (controller == 0) { playerText.text = "Press 'W/A/S/D' to move."; } else { playerText.text = "Press 'ARROW -KEYS' to move."; } lastTutorialTime = Time.time; } else if (tutorialState == 1 && (Input.GetAxis("Horizontal" + controller) != 0 || Input.GetAxis("Vertical" + controller) != 0)) { tutorialState = 2; if (controller == 0) { playerText.text = "Press 'E' to bark."; } else { playerText.text = "Press 'P' to bark."; } lastTutorialTime = Time.time; } if (tutorialState == 5 && Input.anyKeyDown) { tutorialState = -1; playerText.text = ""; } } if (Input.GetButtonDown("DropPile" + controller)) { if (tutorialState == 3) { tutorialState = 4; if (controller == 0) { playerText.text = "Press 'Q' to eat a sheep for a pile."; } else { playerText.text = "Press 'O' to eat a sheep for a pile."; } lastTutorialTime = Time.time; } if (piles > 0) { Instantiate(pilePrefab, transform.position, transform.rotation, null); SheepManager.instance.AddPile(transform.position); piles--; pileText.text = "" + piles; } SheepManager.instance.SpawnPopup(transform.position, "Piles x" + piles); } if (Input.GetButtonDown("Bark" + controller)) { if (tutorialState == 2) { tutorialState = 3; if (controller == 0) { playerText.text = "Press 'space' to drop a pile."; } else { playerText.text = "Press 'L' to drop a pile."; } lastTutorialTime = Time.time; } barkParticles.Play(); barkLineParticles.Play(); SheepManager.instance.OnBark(transform.position); SheepManager.instance.SpawnPopup(transform.position, wuffs[Random.Range(0, wuffs.Length)]); sound.pitch = Random.Range(0.9F, 1.1F); sound.PlayOneShot(wuffSounds[Random.Range(0, wuffSounds.Length)]); } // Kill closest sheep if possible if (Input.GetButtonDown("Kill" + controller)) { if (tutorialState == 4) { tutorialState = 5; playerText.text = "Good luck..."; lastTutorialTime = Time.time; } // Kill closest sheep if possible if (SheepManager.instance.KillClosest(transform.position)) { if (piles < 3) { piles++; pileText.text = "" + piles; SheepManager.instance.SpawnPopup(transform.position, "Piles x" + piles); } piles = Mathf.Min(3, piles + pilesPerKill); pileText.text = "" + piles; } } Vector3 mov = new Vector3(Input.GetAxis("Horizontal" + controller), 0, Input.GetAxis("Vertical" + controller)); //agent.destination = transform.position + 0.5F * mov.normalized * Mathf.Min(mov.magnitude, 1.0F); mov = agent.speed * mov.normalized * Mathf.Min(mov.magnitude, 1.0F); agent.Move(Time.deltaTime * mov); anim.SetFloat("velocity", mov.magnitude); if (mov.sqrMagnitude > 0) { transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.LookRotation(mov, Vector3.up), Time.deltaTime * agent.angularSpeed); } } }
// Update is called once per frame private void Update() { if (!photonView.IsMine) { return; } //Debug.Log(scoop); //scoop //bool scoop = gun.sniperMode; //var scoopDir = new Vector3(0.15f/zoomSteps,-0.101f/zoomSteps,2.311f/zoomSteps); //Debug.Log(scoopDir); var myAxis = new Vector3(0, 0, 1); var horizontalPotision = Input.GetAxis("Horizontal"); var verticalPotision = Input.GetAxis("Vertical"); var horizontalRotation = Input.GetAxis("HorizontalRot"); var verticalRotation = Input.GetAxis("VerticalRot"); var changeCoordinate = new Quaternion(); //Debug // var juuji = Input.GetAxis("Sniper"); // Debug.Log(juuji); // if(Input.GetAxis("Sniper")>0 && !Input.GetButton("Fire1")){ // scoop = true; // }else if(Input.GetAxis("Sniper")<0 && !Input.GetButton("Fire1")){ // scoop = false; // } // if(scoop == false) // { // zoom = cameraZoom; // SniperMode.SetActive(false); // }else{ // zoom = cameraZoom * sniperZoom; // SniperMode.SetActive(true); // } //ベクトルの規格化(座標変換) changeCoordinate.SetFromToRotation(myAxis, transform.forward); //movementは入力装置から指定されたベクトル var inputMove = new Vector3(horizontalPotision, 0, verticalPotision); var inputRot = new Vector3(horizontalRotation, 0, 0); //var inputRot = new Vector3(horizontalRotation,0,verticalRotation); var movment = changeCoordinate * inputMove; var rot = changeCoordinate * inputRot; //Debug.Log(horizontalRotation); //Debug.Log(rot.magnitude); animator.SetFloat("Speed", movment.magnitude); if (rot.magnitude > 0) { Quaternion newDirection = Quaternion.LookRotation(rot); //if(Input.GetButton("Quick Turn")) //{ // currentTurnSpeed = quickTurnSpeed; //}else{ currentTurnSpeed = turnSpeed; //} transform.rotation = Quaternion.Slerp(transform.rotation, newDirection, Time.deltaTime * currentTurnSpeed); } if (!Input.GetButton("Fire1")) { //Scoop.SetActive(false); if (myCam.fieldOfView < initialFOV) { myCam.fieldOfView += zoom / zoomSteps; //if(scoop == true){ // visionCamera.transform.position -= changeCoordinate * scoopDir; //} } characterController.Move(movment * Time.deltaTime * moveSpeed); } else { if (myCam.fieldOfView > initialFOV - zoom) { myCam.fieldOfView -= zoom / zoomSteps; // if(scoop == true){ // visionCamera.transform.position += changeCoordinate * scoopDir; // if(myCam.fieldOfView < initialFOV - zoom/2){ // Scoop.SetActive(true); // } // } } } }
// Update is called once per frame void Update() { navMeshAgent.Move(Vector3.right * CarSpeed); }