// Update is called once per frame. void Update() { // If the rig, main camera, and character controller are valid. if (Rig != null && MainCamera != null && Character != null) { // Update the character controller's height. Character.height = MainCamera.transform.position.y - Rig.transform.position.y; // Update the character controller's center. Vector3 center = Character.center; center.y = -Character.height / 2.0f; Character.center = center; // Calculate the movement of the character controller based on the main camera (i.e., user's head). Vector3 movement = MainCamera.transform.position - Character.transform.position; // Apply gravity if indicated. if (UseGravity) { movement.y = Physics.gravity.y * Time.deltaTime; } // Apply the movement. Character.Move(movement); // Begin locomotion. if (CanBeginLocomotion() && BeginLocomotion()) { // Determine the character controller's world location. Vector3 characterLocation = Character.transform.position; // Move the rig and camera to the character controller's world location. Rig.MoveCameraToWorldLocation(characterLocation); // End locomotion. EndLocomotion(); } } }
// Update is called once per frame. void Update() { // If the rig and main camera are valid. if (Rig != null && MainCamera != null) { // Calculate the travel vector based on the user's head and the rig. Vector3 travelVector = MainCamera.transform.position - Rig.transform.position; // Ignore any height value. travelVector.y = 0.0f; // Activate human joystick if the travel vector is larger than the radius. if (travelVector.magnitude >= Radius) { // Calculate the ratio of the travel vector compared to the radius. float ratio = travelVector.magnitude / Radius; // Normalize the travel vector for multiplication. travelVector.Normalize(); // Scale the travel vector by the ratio and speed per second (which requires deltaTime). Vector3 movement = travelVector * ratio * Speed * Time.deltaTime; // Begin locomotion. if (CanBeginLocomotion() && BeginLocomotion()) { // Determine the camera's new world location. Vector3 newLocation = MainCamera.transform.position + movement; // Move the rig and camera to the character controller's world location. Rig.MoveCameraToWorldLocation(newLocation); // End locomotion. EndLocomotion(); } } // If the no-travel zone is valid. if (NoTravelZone != null) { // Move the no-travel zone to match the rig. NoTravelZone.transform.position = Rig.transform.position; // Scale the NoTravelZone to match the radius. float originalHeight = NoTravelZone.transform.localScale.y; NoTravelZone.transform.localScale = new Vector3(Radius, originalHeight, Radius); } } }
// Update is called once per frame. void Update() { // If the rig, main camera, and character controller are valid. if (Rig != null && MainCamera != null && Character != null) { // Update the character controller's height. Character.height = MainCamera.transform.position.y - Rig.transform.position.y + offset; // Update the character controller's center. Vector3 center = Character.center; center.y = -Character.height / 2.0f; Character.center = center; Vector3 newPos = MainCamera.transform.position; // Maintain Old RigidBody Y Position newPos.y = RigidBodyCharacter.position.y; RigidBodyCharacter.MovePosition(newPos); // Begin locomotion. if (CanBeginLocomotion() && BeginLocomotion()) { // Determine the character controller's world location. Vector3 characterLocation = Character.transform.position; characterLocation.y -= offset; if (!VirtualBodyScript.CollisionFlag) { characterLocation.x = MainCamera.transform.position.x; characterLocation.z = MainCamera.transform.position.z; } // Move the rig and camera to the character controller's world location. Rig.MoveCameraToWorldLocation(characterLocation); // End locomotion. EndLocomotion(); } } }
// Update is called once per frame. void Update() { // If the rig and main camera are valid. if (Rig != null && MainCamera != null) { // Determine whether head steering is active and what the magnitude is. bool steering = false; float magnitude = 0.0f; // Get the primary 2D axis and button. InputFeatureUsage <Vector2> axisFeature = CommonUsages.primary2DAxis; InputFeatureUsage <bool> buttonFeature = CommonUsages.primary2DAxisClick; // For each controller. for (int i = 0; i < Controllers.Count; i++) { // Fetch the controller. XRController controller = Controllers[i]; // If the controller is valid and enabled. if (controller != null && controller.enableInputActions) { // Fetch the controller's device. InputDevice device = controller.inputDevice; // Try to get the current state of the device's primary 2D axis and button. Vector2 axis; bool button; if (device.TryGetFeatureValue(axisFeature, out axis) && device.TryGetFeatureValue(buttonFeature, out button)) { // Activate steering and add the magnitude if the button is down. if (button) { steering = true; magnitude += axis.y; } } } } // If steering is active, move the rig. if (steering) { // Calculate the movement of the rig based on the user's head direction. Vector3 movement = MainCamera.transform.forward; movement.y = 0.0f; movement.Normalize(); // Scale the travel by the magnitude and speed per second (which requires deltaTime). movement *= magnitude * Speed * Time.deltaTime; // Begin locomotion. if (CanBeginLocomotion() && BeginLocomotion()) { // Determine the camera's new world location. Vector3 newLocation = MainCamera.transform.position + movement; // Move the rig and camera to the character controller's world location. Rig.MoveCameraToWorldLocation(newLocation); // End locomotion. EndLocomotion(); } } } }
// Update is called once per frame. void Update() { // If the rig, main camera, and character controller are valid. if (Rig != null && MainCamera != null && Character != null) { // Determine whether scaled walking is active. bool scaled = false; // Get the button. InputFeatureUsage <bool> button = InputButtonUsage[(int)m_Button]; // For each controller. for (int i = 0; i < Controllers.Count; i++) { // Fetch the controller. XRController controller = Controllers[i]; // If the controller is valid and enabled. if (controller != null && controller.enableInputActions) { // Fetch the controller's device. InputDevice device = controller.inputDevice; // Try to get the current state of the device's button. bool buttonDown; if (device.TryGetFeatureValue(button, out buttonDown)) { // Activate scaled walking if the button is down. if (buttonDown) { scaled = true; } } } } // Update the character controller's height. Character.height = MainCamera.transform.position.y - Rig.transform.position.y; // Update the character controller's center. Vector3 center = Character.center; center.y = -Character.height / 2.0f; Character.center = center; // Calculate the movement of the character controller based on the main camera (i.e., user's head). Vector3 movement = MainCamera.transform.position - Character.transform.position; // If scaled walking is active. if (scaled) { // Scale the movement as indicated. movement *= Scale; } // Apply gravity if indicated. if (UseGravity) { movement.y = Physics.gravity.y * Time.deltaTime; } // Apply the movement. Character.Move(movement); // Begin locomotion. if (CanBeginLocomotion() && BeginLocomotion()) { // Determine the character controller's world location. Vector3 characterLocation = Character.transform.position; // Move the rig and camera to the character controller's world location. Rig.MoveCameraToWorldLocation(characterLocation); // End locomotion. EndLocomotion(); } } }