public void Move(Vector3 directionVector) { // move along with direction. if (character == null) { return; } inputDirection = directionVector; if (directionVector != Vector3.zero) { var directionLength = directionVector.magnitude; directionVector = directionVector / directionLength; directionLength = Mathf.Min(1, directionLength); directionLength = directionLength * directionLength; directionVector = directionVector * directionLength; } Quaternion rotation = transform.rotation; if (TPSViewPart) { rotation = TPSViewPart.transform.rotation; } Vector3 angle = rotation.eulerAngles; angle.x = 0; angle.z = 0; rotation.eulerAngles = angle; character.MoveTo(rotation * directionVector); }
public void Move(Vector3 directionVector) { // move along with direction. if (character == null) { return; } inputDirection = directionVector; if (directionVector != Vector3.zero) { var directionLength = directionVector.magnitude; directionVector = directionVector / directionLength; directionLength = Mathf.Min(1, directionLength); directionLength = directionLength * directionLength; directionVector = directionVector * directionLength; if (PlayerView.freeCamera != null && PlayerView.View == PlayerViewType.FreeView) { Quaternion direction = Quaternion.LookRotation(PlayerView.freeCamera.transform.forward); direction.eulerAngles = new Vector3(0, direction.eulerAngles.y, 0); rotationXtemp = direction.eulerAngles.y; rotationX = rotationXtemp; this.transform.rotation = direction; } } Quaternion rotation = transform.rotation; if (PlayerView.FPSCamera) { rotation = PlayerView.FPSCamera.transform.rotation; } Vector3 angle = rotation.eulerAngles; angle.x = 0; angle.z = 0; rotation.eulerAngles = angle; character.MoveTo(rotation * directionVector); }