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

    New Participant
    February 10, 2020
    MajorThurman, I do not have an answer for how to code a double jump, I struggled one million years with a simple jump so I think I'll stop there hahaha. So I can't answer you with the code, but only some theories! That can hopefully point you in the right direction.

    I think the key for a double jump would have to do with 
    Controller.isGrounded. I believe that tells you if your player is in the ground. That's why the code I mentioned in my last post:

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

    Needed to be commented out, in order for you to be able to move while jumping. In C Sharp programming the ! means not (at least in an if, like above). And remember that Controller.isGrounded means "is in the ground" so the code above means something like:

    if NOT is in the ground
    THEN movescale = 0

    And I guess movescale 0 means forbid movement. So it means if the player is not in the ground (if the player is in the air, if the player is jumping) don't let them move. That's why we deactivated that and you were now able to move while in the air.

    I think your double jump solution will be around that Controller.isGrounded thingy. Somewhere in the code you probably have some logic that says something like if Controller.isGrounded don't let the player jump again. So you will need to find where that is and find a way to modify that rule so that the jump works again even if the player is !Controller.isGrounded (! = not). But then you'd have to put a limit so that the player doesn't jump and jump and jump and jump and jump and jump and jump and jump and jump and jump and jump and jump and jump and jump and jump and jump and jump (which would be basically flying). So some variable that counts if the player has jumped once, let them jump again, if they have jumped twice then don't let them jump again. Sorry I can't help with the specifics of the code, but I hope that logic gives you a bit of guidance on where to look and what to do. And now I'll be gone because I bought chocolate cereal today and I suddenly had a big urge to eat that right this moment!