Because physics in VR is a very difficult thing to get right and most people don’t try. Those that do are making their own games and keeping the tech to themselves. I publish a rigid body player built to mimic the Boneworks player. Spent 2 months working on it to get it to a usable state.
The character controller does not use physics because it is not a rigid body, you would have to program jumping, gravity, and momentum yourself to “fake physics”
Thank you for your reply. Your controller package looks great.
Honestly, I’m a bit surprised to hear this. I would have expected a jump to be built in to the XR Interaction Toolkit, since it provides components for continuous movement, turning, snap turning, teleporting, and other locomotion controls. Jumping is a common action in VR, and is right in line with those.
Does anyone know if jump support is a planned part of XR Interaction Toolkit, in the future?
It’s not. I wrote my own jumping / movement because of that, however, I do not use physics for that and only the pain character controller. Also still use the device based XR Rig and not the Action based one.
Maybe this gives you an idea how to do it. (Do not take this as a professional solution, because I’m certainly not a pro at this! It simply is one!)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR;
using UnityEngine.XR.Interaction.Toolkit;
public class XR_JumpController : MonoBehaviour
{
public XRNode inputSource;
private InputDevice device;
public AudioClip jumpSound;
public LayerMask CeilingLayer;
public float jumpHeight = 5.0F;
public bool isJumping = false;
private bool lastState = false;
private float jumppos;
public float jumpSpeed = 4.0f;
private float fallingSpeed;
private XRRig rig;
private AudioSource MainSFX;
private Vector2 inputAxis;
private CharacterController character;
void Start()
{
character = GetComponent<CharacterController>();
rig = GetComponent<XRRig>();
MainSFX = GetComponent<AudioSource>();
MainSFX.clip = jumpSound;
InitController();
}
void InitController()
{
device = InputDevices.GetDeviceAtXRNode(inputSource);
}
// Update is called once per frame
void Update()
{
if (!device.isValid)
InitController();
if (SecondaryButtonDown() & this.gameObject.GetComponent<XRMovement>().CheckIfGrounded())
{
isJumping = true;
MainSFX.Play();
jumppos = character.transform.position.y;
character.slopeLimit = 90; // fixes the jump directly in fornt of thing while pressing forward. has to be reset to 45 when isJumping = false
}
if (isJumping)
Jump();
if (HitCeiling())
isJumping = false;
}
public bool HitCeiling()
{
Vector3 rayStart = transform.TransformPoint(character.center);
float rayLength = character.center.y + 0.1f;
bool hasHit = Physics.SphereCast(rayStart, character.radius, Vector3.up, out RaycastHit hitInfo, rayLength, CeilingLayer);
return hasHit;
}
private void Jump()
{
if (character.transform.position.y >= jumppos + jumpHeight)
{
isJumping = false;
character.slopeLimit = 45;
}
character.Move(Vector3.up * jumpSpeed * Time.smoothDeltaTime);
}
public bool SecondaryButtonDown()
{
if (device.TryGetFeatureValue(CommonUsages.secondaryButton, out bool secondaryButtonValue) && secondaryButtonValue)
{
bool tempStatePrimary = secondaryButtonValue;
if (tempStatePrimary != lastState) //Button Down
{
lastState = tempStatePrimary;
return true;
}
}
else
{
lastState = false;
}
return false;
}
}
Thank you very much for that suggestion. I’ll use it as a guide.
Huh - You’re right! I went through the list of VR games I thought had a jump, but very few of them did. I could have sworn Population One had a jump, but nope!
And apparently for good reason - it’s clear that would make some people nauseous.
I should probably reconsider if it’s worth having at all. Maybe a tall step height would work just as well.
I implemented something that may be helpful for this. but you may have had your question answered since then – let me know and if not I’m happy to provide details.