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!
Hey buddy, was wondering if you found any solution to this issue, particularly in solving dynamic player height.
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.
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.
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 ^-^
/************************************************************************************
See SampleFramework license.txt for license terms. Unless required by applicable law
or agreed to in writing, the sample code is provided “AS IS” WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the license for specific
language governing permissions and limitations under the license.
************************************************************************************/
using System;
using UnityEngine;
/// <summary>
/// This component is responsible for moving the character capsule to match the HMD, fading out the camera or blocking movement when
/// collisions occur, and adjusting the character capsule height to match the HMD's offset from the ground.
/// </summary>
public class CharacterCameraConstraint : MonoBehaviour
{
/// <summary>
/// This should be a reference to the OVRCameraRig that is usually a child of the PlayerController.
/// </summary>
[Tooltip("This should be a reference to the OVRCameraRig that is usually a child of the PlayerController.")]
public OVRCameraRig CameraRig;
/// <summary>
/// When true, the character capsule won't grow into upwards geo when the player stands up under a low surface.
/// </summary>
[Tooltip("When true, the camera will be prevented from passing through collidable geometry. This is usually considered uncomfortable for users.")]
public bool EnableCollision;
public LayerMask CollideLayers;
/// <summary>
/// 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.
/// </summary>
[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.")]
public float MaxFade = 1;
/// <summary>
/// This value is used to control how far from the character capsule the HMD must be before the fade to black begins.
/// </summary>
[Tooltip("This value is used to control how far from the character capsule the HMD must be before the fade to black begins.")]
public float FadeMinDistance = 0.25f;
/// <summary>
/// If > 0, the capsule will stretch or shrink so that the top of it is at the camera's y location.
/// Note that if you want the capsule to go a bit higher than the camera you'll need to add your own padding logic.
/// </summary>
public float PreferredHeight = 1.0f;
/// <summary>
/// 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.
/// </summary>
[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.")]
public float FadeMaxDistance = 0.35f;
private readonly Action _cameraUpdateAction;
private readonly Action _preCharacterMovementAction;
//private CapsuleCollider _character;
//private SimpleCapsuleWithStickMovement _simplePlayerController;
private CharacterController _character;
private OVRPlayerController _OVRPlayerController;
CharacterCameraConstraint()
{
_cameraUpdateAction = CameraUpdate;
}
void Awake ()
{
//_character = GetComponent<CapsuleCollider>();
_character = GetComponent<CharacterController>();
_OVRPlayerController = GetComponent<OVRPlayerController>();
}
private void Start()
{
}
void OnEnable()
{
//_simplePlayerController.CameraUpdated += _cameraUpdateAction;
_OVRPlayerController.CameraUpdated += _cameraUpdateAction;
}
void OnDisable()
{
//_simplePlayerController.CameraUpdated -= _cameraUpdateAction;
_OVRPlayerController.CameraUpdated -= _cameraUpdateAction;
}
/// <summary>
/// This method is the handler for the PlayerController.CameraUpdated event, which is used
/// to update the character height based on camera position.
/// </summary>
private void CameraUpdate()
{
// If dynamic height is enabled, try to adjust the controller height to the height of the camera.
if (PreferredHeight > 0.0f)
{
float camHeight = Mathf.Min(CameraRig.centerEyeAnchor.transform.localPosition.y, PreferredHeight);
float newHeight = camHeight;
// If the new height is less than before, or we don't need to check for collision, just accept the new height.
if (camHeight <= _character.height || !EnableCollision)
{
// we're good, do nothing.
}
else
{
// Attempt to increase the controller height to the height of the camera.
// It is important to understand that this will prevent the character from growing into colliding
// geometry, and that the camera might go above the character controller. For instance, ducking through
// a low tunnel and then standing up in the middle would allow the player to see outside the world.
// The CharacterCameraConstraint is designed to detect this problem and provide feedback to the user,
// however it is useful to keep the character controller at a size that fits the space because this would allow
// the player to move to a taller space. If the character controller was simply made as tall as the camera wanted,
// the player would then be stuck and unable to move at all until the player ducked back down to the
// necessary elevation.
Vector3 rayStart = _character.transform.position;
RaycastHit info;
Vector3 rayEnd = rayStart;
rayEnd.y += newHeight * 4;
Debug.DrawLine(rayStart, rayEnd);
if (Physics.SphereCast(rayStart, _character.radius * 0.2f, Vector3.up, out info, 4.0f,
CollideLayers, QueryTriggerInteraction.Ignore))
{
newHeight = info.distance + _character.radius;
} // else, no hit, we're fine
}
// camHeight/newHeight here is tracking space distance from player's eyes to player's feet.
// But note that the player controller is centered in the middle of the rigid body.
// So we move the camera position down by half the player's height to get the eye position to line
// up with the top of the capsule.
_character.height = newHeight;
Vector3 newCamPos = CameraRig.transform.localPosition;
newCamPos.y = -_character.height * 0.5f;
//CameraRig.transform.localPosition = newCamPos;
_character.center = new Vector3(0, newCamPos.y, 0);
}
}
}
so I get the preferred height to -1 still not working.
@Loading97 Thanks so much, it works
@Loading97 Thanks!!! it’s worked. You saved me XD