Skip to main content
Participant
June 9, 2013

Help needed to add jump function to OVR Player Controller?

Hi All,

I'm hoping some kind person may be able to help me or point me in the right direction. I started learning Unity a few weeks back before I got the Rift. I decided to try and do a 'moon based' demo as I thought the change in gravity would be fun and it's a good environment for me to experiment with while I learn.

I had it working beautifully before the Rift arrived, able to walk and jump around the lunar landscaper. Since getting the Rift I removed the my old control type (from the 'standard assets' that ship with Unity) and added the Oculus Controller. This works fine apart from I now have no jump function and I've tried a variety of things to get it back with no success. As my lunar environment requires jumping and low gravity, it's proving a bit of a nightmare.

I am a newbie, and I'm sure that the answer is pretty simple so if someone could at least point me in the right direction I would be eternally grateful.

Thanks in advance.
    This topic has been closed for replies.

    31 replies

    Up and Coming
    December 29, 2014
    There is a game "Hiroshi Jump" I believe, where you actually jump and this triggers a jump. This would be DK2 only. Any ideas on how this could be implemented in unity?
    KevinGulling.com
    Up and Coming
    December 29, 2014
    Check the "up" position and if it changes enough up in a short time trigger a jump?
    Inspiring
    December 29, 2014
    The Jump function is in there, it's just disabled since it's usually not a comfortable experience.

    You can enable it by adding this to the end of UpdateMovement() in OVRPlayerController.cs:

    if (Input.GetKey (KeyCode.F))
    Jump ();


    In the inspector for OVRPlayerController, you can mess with Jump Force and Gravity Modifer.
    AMD Ryzen 7 1800X | MSI X370 Titanium | G.Skill 16GB DDR4 3200 | EVGA SuperNOVA 1000 | Corsair Hydro H110i Gigabyte RX Vega 64 x2 | Samsung 960 Evo M.2 500GB | Seagate FireCuda SSHD 2TB | Phanteks ENTHOO EVOLV
    Participant
    December 30, 2014
    "cybereality" wrote:
    The Jump function is in there, it's just disabled since it's usually not a comfortable experience.

    You can enable it by adding this to the end of UpdateMovement() in OVRPlayerController.cs:

    if (Input.GetKey (KeyCode.F))
    Jump ();


    In the inspector for OVRPlayerController, you can mess with Jump Force and Gravity Modifer.


    Think it is more comfortable if you also // out the positional movement stop if not grounded (so you keep momentum on running jumps and such).

    So, in OVRPlayerController:
    // No positional movement if we are in the air
    if (!Controller.isGrounded)
    MoveScale = 0.0f;


    becomes:
    // No positional movement if we are in the air
    //if (!Controller.isGrounded)
    // MoveScale = 0.0f;


    Using Space is more natural for a jump too (for me at least), can reassign F (or desired key) to the menu right in the inspector. Add in a a bit more code to avoid continuous "hopping", a few other little changes and it fares decently I think.
    Inspiring
    December 30, 2014
    Ah yes, I forgot to mention those two things as well.
    AMD Ryzen 7 1800X | MSI X370 Titanium | G.Skill 16GB DDR4 3200 | EVGA SuperNOVA 1000 | Corsair Hydro H110i Gigabyte RX Vega 64 x2 | Samsung 960 Evo M.2 500GB | Seagate FireCuda SSHD 2TB | Phanteks ENTHOO EVOLV
    Up and Coming
    January 1, 2015
    I just changed the float value to make my character able to move while jumping and that seemed to work. My problem is that when I jump I shoot up really, really fast, almost instantly reaching the max height. Changing gravity only reduces the speed of the descent. I will try adding the camera to the Unity controller. Thanks.
    Ordered: June 4th Status: Strapped to my ugly mug ON, Canada
    May 30, 2016
    can someone please know how to implement the jump with the headset gear vr touch controls?
    Up and Coming
    June 1, 2016
    so much for first person mario :-p
    New Participant
    February 3, 2020
    Here's what worked for me, written in baby steps for beginners (because I'm a beginner and some people here speak like if everybody knew what we were doing but nooo, some of us we have baby level programming skills, so hopefully this helps newbies like me go step by step).

    - STEP 1
    On Unity hierarchy (left pane) click on OVRPlayerController

    - STEP 2
    On the right pane search OVR Player Controller (Script) and right click > Edit Script

    - STEP 3
    On the script go to where it says public virtual void UpdateMovement()
    {

    - STEP 4
    Click the weird parentheses { and your editor should highlight the corresponding closing weird parentheses }. This is so that you know where to write. Anywhere inside the { and the corresponding closing } of the function UpdateMovement() write the below:

    if (Input.GetKeyDown("x") || OVRInput.GetDown(OVRInput.Button.One))
        Jump();

    This means if you click x on your keyboard (after you click play in Unity) or the button A on the Oculus controller (after build) you jump. If you don't want the A button, find whichever controller button by Googling unity-ovrinput and search where it says 'Example Usage'.

    - STEP 5
    Also ensure that JUMP is activated. It should look like this:

    /// <summary>
    /// Jump! Must be enabled manually.
    /// </summary>
    public bool Jump()
    {
    if (!Controller.isGrounded)
    return false;
    MoveThrottle += new Vector3(0, transform.lossyScale.y * JumpForce, 0);
    return true;
    }

    If you see /// in other lines, delete (that comments the lines out, which we don't want, except for the first three lines above).

    This will let you jump but lamely (yes, lamely, I invented that word to mean of a lame nature... then I Googled and it means something different :o but I will use it here for "a lame thing"). So you jump lamely because if you are walking forward and you jump it will just jump up (but not keep going forward, and nobody jumps like that except Boston Dynamics' Alpha Dog and other robots bue we want a HUMAN jump). To fix the lameliness of the jump, comment - meaning add /// - to the "No positional movement in air" in that same script. It should look like this:

    // No positional movement if we are in the air
    //if (!Controller.isGrounded)
    // MoveScale = 0.0f;

    You could also delete instead of comment out but I prefer commenting because whenever I delete lines or files from my computer I feel that I might need them in the future and I will regret deleting and then it will be a catastrophe but in reality I never do so I have files that I created in 2012 that I had never opened but that's a subject for another day. Short story long, delete or comment it, whatever you prefer.

    Now you should be able to jump up AND forward/sideways at the same time, like a proper human.

    - STEP 6
    Go to your game and jump and then find out another problem and search the internet for an answer. Rinse and repeat endlessly.
    New Participant
    February 7, 2020

    diegomsgg said:

    Here's what worked for me, written in baby steps for beginners (because I'm a beginner and some people here speak like if everybody knew what we were doing but nooo, some of us we have baby level programming skills, so hopefully this helps newbies like me go step by step).

    - STEP 1
    On Unity hierarchy (left pane) click on OVRPlayerController

    - STEP 2
    On the right pane search OVR Player Controller (Script) and right click > Edit Script

    - STEP 3
    On the script go to where it says public virtual void UpdateMovement()
    {

    - STEP 4
    Click the weird parentheses { and your editor should highlight the corresponding closing weird parentheses }. This is so that you know where to write. Anywhere inside the { and the corresponding closing } of the function UpdateMovement() write the below:

    if (Input.GetKeyDown("x") || OVRInput.GetDown(OVRInput.Button.One))
        Jump();

    This means if you click x on your keyboard (after you click play in Unity) or the button A on the Oculus controller (after build) you jump. If you don't want the A button, find whichever controller button by Googling unity-ovrinput and search where it says 'Example Usage'.

    - STEP 5
    Also ensure that JUMP is activated. It should look like this:

    /// <summary>
    /// Jump! Must be enabled manually.
    /// </summary>
    public bool Jump()
    {
    if (!Controller.isGrounded)
    return false;
    MoveThrottle += new Vector3(0, transform.lossyScale.y * JumpForce, 0);
    return true;
    }

    If you see /// in other lines, delete (that comments the lines out, which we don't want, except for the first three lines above).

    This will let you jump but lamely (yes, lamely, I invented that word to mean of a lame nature... then I Googled and it means something different :o but I will use it here for "a lame thing"). So you jump lamely because if you are walking forward and you jump it will just jump up (but not keep going forward, and nobody jumps like that except Boston Dynamics' Alpha Dog and other robots bue we want a HUMAN jump). To fix the lameliness of the jump, comment - meaning add /// - to the "No positional movement in air" in that same script. It should look like this:

    // No positional movement if we are in the air
    //if (!Controller.isGrounded)
    // MoveScale = 0.0f;

    You could also delete instead of comment out but I prefer commenting because whenever I delete lines or files from my computer I feel that I might need them in the future and I will regret deleting and then it will be a catastrophe but in reality I never do so I have files that I created in 2012 that I had never opened but that's a subject for another day. Short story long, delete or comment it, whatever you prefer.

    Now you should be able to jump up AND forward/sideways at the same time, like a proper human.

    - STEP 6
    Go to your game and jump and then find out another problem and search the internet for an answer. Rinse and repeat endlessly.


    Dude! from one beginner to another.  You're a legend!

    Worked first time!

    Here's another on for you then, how on earth would you code a double jump? :)