public void Teleport(string plane, Vector3 pos, Vector3?rotation) { Vector3 rot = rotation ?? transform.eulerAngles; pos.y = 0; navPlane = NavigationPlane.FindPlane(plane); NavigationPlane.ValidMove(ref pos, ref navPlane); transform.position = pos; transform.eulerAngles = rot; targetRotation = transform.rotation; }
void Update() { float speed = 0; if (!GameStateManager.IsMenu && GameStateManager.HasFocus) { Vector3 oldPos = transform.localPosition; Quaternion cameraForward = Quaternion.Euler(0, cam.eulerAngles.y, 0); Vector3 moveVector = cameraForward * new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); if (moveVector.sqrMagnitude > 0.01f) { speed = moveVector.magnitude; if (speed > 1) { moveVector /= speed; speed = 1; } float accSpeed = moveSpeed; if (GameStateManager.State.currentGameUpgrade > 3) { accSpeed *= 1.5f; } Vector3 newPos = transform.localPosition + Time.deltaTime * accSpeed * moveVector; NavigationPlane.ValidMove(ref newPos, ref navPlane); transform.localPosition = newPos; targetRotation = Quaternion.LookRotation(moveVector); } transform.localRotation = Quaternion.RotateTowards(transform.localRotation, targetRotation, spinSpeed * Time.deltaTime); } animator.speed = 10.0f * speed; Vector3 pos = positionInteraction.localPosition; pos.y = offsetYInteraction * (1.0f / cam.up.y); positionInteraction.localPosition = pos; }