Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. Unity wants to learn about your experiences working on a Unity project today. We'd like to hear from you via this survey.
    Dismiss Notice
  3. Unity 2020 LTS & Unity 2021.1 have been released.
    Dismiss Notice
  4. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  5. Read here for Unity's latest plans on OpenXR.
    Dismiss Notice

Dynamic Height checkbox not appearing for the Character Camera Constraint (Script)

Discussion in 'AR/VR (XR) Discussion' started by robegilm, Jan 23, 2020.

  1. robegilm

    robegilm

    Joined:
    Jan 23, 2020
    Posts:
    2
    Hi I have done all the necessary steps in order to get VR working but am stopped when I must check the dynamic height option in the Character Camera constraint. I am using the Oculus integration asset and replaced the original camera with the OVRPlayerController and set the tracking origin type for the OVRCameraRig to floor level, but when I apply the Character Camera Constraint (Script) component I do not see the option for dynamic height, and when I place hands (CustomHandLeft and CustomHandRight) into the LocalAvatar Prefab that I placed in the TrackingSpace, the hands show up at the bottom center of the OVRPlayerController instead of following the L Touch and R Touch. Some clarity or help would be great as soon as possible! Thanks!
     
  2. L-Barton

    L-Barton

    Joined:
    Feb 15, 2020
    Posts:
    1
    Hey buddy, was wondering if you found any solution to this issue, particularly in solving dynamic player height.
     
  3. robegilm

    robegilm

    Joined:
    Jan 23, 2020
    Posts:
    2
    No, never figured it out. I looked through the code for player constraint and saw the height control for dynamic height but not the Boolean.
     
  4. Ruud3DV

    Ruud3DV

    Joined:
    Jan 25, 2016
    Posts:
    6
    Looking at the script it shows you have to set the Preferred Height to > 0 for the height to be dynamically adjusted. The default value is -1 which is equivalent to disabled Dynamic Height in a previous version of the script.

    With version 13 of the Oculus Integration the Character Camera Constraint can only adjust the height. The fade and collision detection are completely removed from the script for some reason, only the inspector variables are left.
     
    Last edited: Feb 27, 2020
  5. Loading97

    Loading97

    Joined:
    Apr 16, 2017
    Posts:
    3
    I looked everywhere and didn't find a solution, so i decided to dive into the coding and fix it myself. So, instead of downgrading, copy the whole script i have there and paste it on your file, or replace your files directly. I what needed to change.

    For some reason, they updated how the prefab looks, but they didn't fix all of their scripts to go along with the prefab. Basically, the script was trying to find components that were replaced.

    This still has the issue that Ruud3DV was talking about, that it only adjusts the height and that the rest was removed, i was planing on adding, but was having some issues with it, so i decided to postpone it and do it when i actually need it

    Have a good development, and most of all, have fun making games ^-^

    Code (CSharp):
    1. /************************************************************************************
    2.  
    3. See SampleFramework license.txt for license terms.  Unless required by applicable law
    4. or agreed to in writing, the sample code is provided “AS IS” WITHOUT WARRANTIES OR
    5. CONDITIONS OF ANY KIND, either express or implied.  See the license for specific
    6. language governing permissions and limitations under the license.
    7.  
    8. ************************************************************************************/
    9.  
    10. using System;
    11. using UnityEngine;
    12.  
    13. /// <summary>
    14. /// This component is responsible for moving the character capsule to match the HMD, fading out the camera or blocking movement when
    15. /// collisions occur, and adjusting the character capsule height to match the HMD's offset from the ground.
    16. /// </summary>
    17. public class CharacterCameraConstraint : MonoBehaviour
    18. {
    19.     /// <summary>
    20.     /// This should be a reference to the OVRCameraRig that is usually a child of the PlayerController.
    21.     /// </summary>
    22.     [Tooltip("This should be a reference to the OVRCameraRig that is usually a child of the PlayerController.")]
    23.     public OVRCameraRig CameraRig;
    24.  
    25.     /// <summary>
    26.     /// When true, the character capsule won't grow into upwards geo when the player stands up under a low surface.
    27.     /// </summary>
    28.     [Tooltip("When true, the camera will be prevented from passing through collidable geometry. This is usually considered uncomfortable for users.")]
    29.     public bool EnableCollision;
    30.     public LayerMask CollideLayers;
    31.  
    32.     /// <summary>
    33.     /// This should be set to 1 to make the screen completely fade out when the HMD is inside world geometry. Lesser values can be useful for testing.
    34.     /// </summary>
    35.     [Tooltip("This should be set to 1 to make the screen completely fade out when the HMD is inside world geometry. Lesser values can be useful for testing.")]
    36.     public float MaxFade = 1;
    37.  
    38.     /// <summary>
    39.     /// This value is used to control how far from the character capsule the HMD must be before the fade to black begins.
    40.     /// </summary>
    41.     [Tooltip("This value is used to control how far from the character capsule the HMD must be before the fade to black begins.")]
    42.     public float FadeMinDistance = 0.25f;
    43.  
    44.     /// <summary>
    45.     /// If > 0, the capsule will stretch or shrink so that the top of it is at the camera's y location.
    46.     /// Note that if you want the capsule to go a bit higher than the camera you'll need to add your own padding logic.
    47.     /// </summary>
    48.     public float PreferredHeight = 1.0f;
    49.  
    50.     /// <summary>
    51.     /// This value is used to control how far from the character capsule the HMD must be before the fade to black is complete.
    52.     /// This should be tuned so that it is fully faded in before the camera will clip geometry that the player should not be able see beyond.
    53.     /// </summary>
    54.     [Tooltip("This value is used to control how far from the character capsule the HMD must be before the fade to black is complete. This should be tuned so that it is fully faded in before the camera will clip geometry that the player should not be able see beyond.")]
    55.     public float FadeMaxDistance = 0.35f;
    56.  
    57.     private readonly Action _cameraUpdateAction;
    58.     private readonly Action _preCharacterMovementAction;
    59.  
    60.     //private CapsuleCollider _character;
    61.     //private SimpleCapsuleWithStickMovement _simplePlayerController;
    62.     private CharacterController _character;
    63.     private OVRPlayerController _OVRPlayerController;
    64.  
    65.     CharacterCameraConstraint()
    66.     {
    67.         _cameraUpdateAction = CameraUpdate;
    68.     }
    69.  
    70.     void Awake ()
    71.     {
    72.         //_character = GetComponent<CapsuleCollider>();
    73.         _character = GetComponent<CharacterController>();
    74.         _OVRPlayerController = GetComponent<OVRPlayerController>();
    75.     }
    76.  
    77.     private void Start()
    78.     {
    79.     }
    80.  
    81.     void OnEnable()
    82.     {
    83.         //_simplePlayerController.CameraUpdated += _cameraUpdateAction;
    84.         _OVRPlayerController.CameraUpdated += _cameraUpdateAction;
    85.     }
    86.  
    87.     void OnDisable()
    88.     {
    89.         //_simplePlayerController.CameraUpdated -= _cameraUpdateAction;
    90.         _OVRPlayerController.CameraUpdated -= _cameraUpdateAction;
    91.     }
    92.  
    93.     /// <summary>
    94.     /// This method is the handler for the PlayerController.CameraUpdated event, which is used
    95.     /// to update the character height based on camera position.
    96.     /// </summary>
    97.     private void CameraUpdate()
    98.     {
    99.         // If dynamic height is enabled, try to adjust the controller height to the height of the camera.
    100.         if (PreferredHeight > 0.0f)
    101.         {
    102.             float camHeight = Mathf.Min(CameraRig.centerEyeAnchor.transform.localPosition.y, PreferredHeight);
    103.             float newHeight = camHeight;
    104.            
    105.             // If the new height is less than before, or we don't need to check for collision, just accept the new height.
    106.             if (camHeight <= _character.height || !EnableCollision)
    107.             {
    108.                 // we're good, do nothing.
    109.             }
    110.             else
    111.             {
    112.                 // Attempt to increase the controller height to the height of the camera.
    113.                 // It is important to understand that this will prevent the character from growing into colliding
    114.                 // geometry, and that the camera might go above the character controller. For instance, ducking through
    115.                 // a low tunnel and then standing up in the middle would allow the player to see outside the world.
    116.                 // The CharacterCameraConstraint is designed to detect this problem and provide feedback to the user,
    117.                 // however it is useful to keep the character controller at a size that fits the space because this would allow
    118.                 // the player to move to a taller space. If the character controller was simply made as tall as the camera wanted,
    119.                 // the player would then be stuck and unable to move at all until the player ducked back down to the
    120.                 // necessary elevation.
    121.                 Vector3 rayStart = _character.transform.position;
    122.                 RaycastHit info;
    123.                 Vector3 rayEnd = rayStart;
    124.                 rayEnd.y += newHeight * 4;
    125.                 Debug.DrawLine(rayStart, rayEnd);
    126.                 if (Physics.SphereCast(rayStart, _character.radius * 0.2f, Vector3.up, out info, 4.0f,
    127.                     CollideLayers, QueryTriggerInteraction.Ignore))
    128.                 {
    129.                     newHeight = info.distance + _character.radius;
    130.                 } // else, no hit, we're fine
    131.             }
    132.  
    133.             // camHeight/newHeight here is tracking space distance from player's eyes to player's feet.
    134.             // But note that the player controller is centered in the middle of the rigid body.
    135.             // So we move the camera position down by half the player's height to get the eye position to line
    136.             // up with the top of the capsule.
    137.             _character.height = newHeight;
    138.             Vector3 newCamPos = CameraRig.transform.localPosition;
    139.             newCamPos.y = -_character.height * 0.5f;
    140.             //CameraRig.transform.localPosition = newCamPos;
    141.             _character.center = new Vector3(0, newCamPos.y, 0);
    142.         }
    143.        
    144.     }
    145.  
    146. }
    147.  
     

    Attached Files:

    RingoKam and firepro20 like this.
  6. kiki2009

    kiki2009

    Joined:
    Sep 19, 2020
    Posts:
    1
    so I get the preferred height to -1 still not working.
     
  7. LordAlexander

    LordAlexander

    Joined:
    Oct 5, 2014
    Posts:
    2
unityunity