// Update is called once per frame void FixedUpdate() { // The direction from the bird to the controller (which represents either the head's view direction or the mouse position). Vector3 direction = Bearing.attractor(main_character.forward, main_controller.forward); float target_angle = Vector3.SignedAngle(main_character.up, direction, main_character.forward) * Mathf.Deg2Rad; // Distance from satellite to controller (which represents either the head's view direction or the mouse position). float target_distance = Vector3.Angle(main_character.forward, main_controller.forward) * Mathf.Deg2Rad; target_distance = Mathf.Clamp01(target_distance / (Mathf.PI / 4)); /*satellite radius, not divided by 2 because Actuator goes twice as far as head movement*/ // Return the composite input direction. Vector2 input_direction = new Vector2(-Mathf.Sin(target_angle), Mathf.Cos(target_angle)) * target_distance * acceleration; // add velocity based on input planetaria_rigidbody.relative_velocity += input_direction * Time.deltaTime; Vector2 velocity = planetaria_rigidbody.relative_velocity; if (planetaria_rigidbody.relative_velocity.magnitude > max_speed) { planetaria_rigidbody.relative_velocity = planetaria_rigidbody.relative_velocity.normalized * max_speed; } }
/// <summary> /// Inspector - Get the input direction based on the virtual reality headset's view direction (or mouse position in Editor mode). /// </summary> /// <returns>The position/direction the player is looking relative to the satellite.</returns> public static Vector2 get_compound_axes() // FIXME: the respawn zone in ghost mode shifts in direction of velocity { if (!main_character || !main_controller) { main_character = GameObject.FindObjectOfType <Satellite>().gameObject.transform; main_controller = GameObject.FindObjectOfType <PlanetariaActuator>().gameObject.internal_game_object.transform; } // Supposed to be called if no controller exists (or hasn't been used for 20 seconds). // In which case: use the head's orientation (or mouse) as a controller. // The direction from the satellite to the controller (which represents either the head's view direction or the mouse position). Vector3 direction = Bearing.attractor(main_character.forward, main_controller.forward); float target_angle = Vector3.SignedAngle(main_character.up, direction, main_character.forward) * Mathf.Deg2Rad; // Distance from satellite to controller (which represents either the head's view direction or the mouse position). float target_distance = Vector3.Angle(main_character.forward, main_controller.forward) * Mathf.Deg2Rad; target_distance = Mathf.Clamp01((target_distance - 0.03f /*satellite radius, not divided by 2 because Actuator goes twice as far as head movement*/) / 0.4f); // Return the composite input direction. Vector2 input_direction = new Vector2(-Mathf.Sin(target_angle), Mathf.Cos(target_angle)) * target_distance; return(input_direction); }