- Home /
is it possible to edit the Continuous Move provider (Action based) to add a jump feature?
Hi,
I am using Open XR and the new input system to make a demo and everything is working, I can move, look around and interact with objects, but I can't find a way to add a jump ability that works with my player set up. nor can I find where the script for the movement is being executed.
I have added a jump button to the control scheme and have tried to implement the jump feature in a separate script, but when I try it either jumps a small step then falls or just flies straight up without stopping.
Below is a pic of the character inspector
If you know how to implement a jump onto this rig using the existing movement providers or where the script for movement is executed please let me know.
Of course if you can think of a better way to implement this please do share.
I met the same problem. Do you have resolution now?,I have same problem. Do you have resolution now?
Answer by LifehackersTW · May 23 at 01:55 PM
Hi @doleary-3800 , The question was here for a long while. I am not sure if you have a solution for this already or not. I was also looking for a way to implement jump, but I still can't find one.
This is my implementation. I am not sure if this is a good solution, but I basically disabled the gravity on Continuous Move Provider, and calculate all the vertical velocity on my own.
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.XR.Interaction.Toolkit;
public class JumpLocomotionProvider : LocomotionProvider
{
public float jumpSpeed = 2f;
[SerializeField] private InputActionProperty inputActionProperty;
[SerializeField] private CharacterController playerController;
private Vector3 _verticalSpeed = Vector3.zero;
private bool _downwardCollided = false;
void Update()
{
if(playerController.isGrounded || _downwardCollided)
{
if (inputActionProperty.action.IsPressed())
{
_verticalSpeed = Vector3.up * jumpSpeed;
}
else
{
_verticalSpeed = Vector3.zero;
}
}
else
{
_verticalSpeed += Physics.gravity * Time.deltaTime;
}
var collisionFlags = playerController.Move(_verticalSpeed * Time.deltaTime);
_downwardCollided = (collisionFlags & CollisionFlags.Below) != 0;
}
}