Welcome to the Oculus Developer Forums!

Your participation on the forum is subject to the Oculus Code of Conduct.

In general, please be respectful and kind. If you violate the Oculus Code of Conduct, your access to the developer forums may be revoked at the discretion of Oculus staff.

How do you enable Jump in OVRCharacterController?

VRfriend2016XVRfriend2016X Posts: 144
Hiro Protagonist
I noticed the class OVRInput.cs has a Jump() method and it says in comments that you must enable it. Where do i enable it?

But also in INput settings JUMP it's set to joystick 3...what exactly is joystick 3 in the xbox one controller?  seems from pictures i saw that is the Y button. but different pictures say different things.
Tagged:

Best Answer

«1

Answers

  • VRfriend2016XVRfriend2016X Posts: 144
    Hiro Protagonist
    Thank you so much. I'll do do that. And so  jooystick 3 will be the                  y Buttong?
    ok anwywas, thanks so much. i'm on my way to discovering more for more game
  • VRfriend2016XVRfriend2016X Posts: 144
    Hiro Protagonist
    vrdaveb said:
    You mean OVRPlayerController? Try adding code like the following to OVRPlayerController.Update():
    if (Input.GetKeyDown(KeyCode.Space)
        Jump();
    Oh yes i just noticed that Jump() method is in OVRPlayerController.   How do you        translate that code to xbox controller "Y BUTTON" for jumping?
  • vrdavebvrdaveb Posts: 1,596 Oculus Staff
    You could use Button.Three or RawButton.Y. See the OVRInput documentation for more detail.
  • VRfriend2016XVRfriend2016X Posts: 144
    Hiro Protagonist
    Thanks so much. So you would do if( Input.getButtonDown(Button.three)  Jump();?

    Thanks alot
  • VRfriend2016XVRfriend2016X Posts: 144
    Hiro Protagonist
    edited July 2016

    =================
    Ok none of that worked. But i found the easiest that doesn't give me errors yet it doesn't work because it's not set up right in the Input settings
    //JUMP Implementation
            if (Input.GetButtonDown("Jump" ))
                Debug.Log("I jumped ");

    My Input settings for Jump, there's one for the keyboard, which is space. but there's another version Jump which is empty. I would if i knew how input "Y" into the POsitive value so that Y is the jump button but anything i type in there, gets erased when i move to another field or exit.



  • vrdavebvrdaveb Posts: 1,596 Oculus Staff
    Use OVRInput, not Input. Also, Button.Three is X. Use Button.Four. Here is exactly the code I just added to OVRPlayerController.Update to confirm it works:


    if (OVRInput.GetDown (OVRInput.Button.Four)) {
    Debug.Log ("Jump!");
    Jump ();
    }


  • VRfriend2016XVRfriend2016X Posts: 144
    Hiro Protagonist
    Here are my Jump settings i have no clue what to put in it and what joystick options to choose etc. Assuming i want the XBOX One's   Y key to be jump
    vrdaveb said:
    Use OVRInput, not Input. Also, Button.Three is X. Use Button.Four. Here is exactly the code I just added to OVRPlayerController.Update to confirm it works:


    if (OVRInput.GetDown (OVRInput.Button.Four)) {
    Debug.Log ("Jump!");
    Jump ();
    }


    How do you have your Input Manager for Jump set up? As you can see mine is totally unfilled. i don't know what to put in it. ANd also you include JUMP()  but i saw jump() in the .cs class and it's a boolean return method....doesn't really have any code to actually do a jump. when i tried to script it it in it gave me an error the last time. I'll try again though
  • vrdavebvrdaveb Posts: 1,596 Oculus Staff
    OVRInput does not use InputManager.asset. When you call OVRPlayerController.Jump(), it queues up a jump for the next Update.
  • VRfriend2016XVRfriend2016X Posts: 144
    Hiro Protagonist
    Ohhh cooool.
  • VRfriend2016XVRfriend2016X Posts: 144
    Hiro Protagonist
    Hey vrdaveb THANKS ALOT> Finally workeD!!!!!!  now it jumps. The jumps are fast and not very high but i can figure out how to change by changing the up force. if i want. Thanks alot!
  • VRfriend2016XVRfriend2016X Posts: 144
    Hiro Protagonist
    I did multiply JumpForce* 4 to make it at least reach a default cube's top.  But i'm noticing the jump is just quickup quick down. like it doesn't follow gravity rules. Anyway to make it a more realistic jump?
  • VRfriend2016XVRfriend2016X Posts: 144
    Hiro Protagonist
    Actually Jumpforce * 4 worked well. i reached the defautl cubes. But the jump is kind of unrealistic. Now i set Gravity modifier to 0.5 instead of default 1 and it's much better but   the movement UP is faster, then the falling down. that's kind of nonrealistic
  • vrdavebvrdaveb Posts: 1,596 Oculus Staff
    The way OVRPlayerController implements jumping is optimized for comfort. In reality, you would be continually accelerating -9.8m/s ^2 on the Y axis, but that would make the user nauseous, so it tries to maintain a constant velocity as much as possible.
  • VRfriend2016XVRfriend2016X Posts: 144
    Hiro Protagonist
    edited July 2016
    Oh I seee......................Ok thanks very much for the info. I just have one little question. How do you jump forwards while moving forwards i can't seem to get it . the jump method is this but i don't know how to modify it so that i can jump forwards too(if i first press and hold forwards, then press the jump key)

    public bool Jump()
        {
            if (!Controller.isGrounded)
                return false;

            MoveThrottle += new Vector3(0, transform.lossyScale.y * JumpForce , 0 );

            return true;
        }

    It seems when you push forwards and then keep pressing forwards and jump. it stops and does a straight up jumpinstead of a forward jump


  • vrdavebvrdaveb Posts: 1,596 Oculus Staff
    If you always want the jump to be forward, you could swap the Y and Z components of the Vector3 there. Or you could just scale the existing MoveThrottle by JumpForce. Then you would have to tweak JumpForce to get the right value.
  • VRfriend2016XVRfriend2016X Posts: 144
    Hiro Protagonist
    vrdaveb said:
    If you always want the jump to be forward, you could swap the Y and Z components of the Vector3 there. Or you could just scale the existing MoveThrottle by JumpForce. Then you would have to tweak JumpForce to get the right value.
    No i don't want to always jump forward, only when the user moves forward
  • VRfriend2016XVRfriend2016X Posts: 144
    Hiro Protagonist
    vrdaveb said:
    If you always want the jump to be forward, you could swap the Y and Z components of the Vector3 there. Or you could just scale the existing MoveThrottle by JumpForce. Then you would have to tweak JumpForce to get the right value.

    Hey i wonder how , what variable is the speed the player is going at a given movment. Cause i could use it
    in MoveThrottle += new Vector3(0, transform.lossyScale.y * JumpForce , 0 );
    and maybe add or multiply something to the Z value instead of letting it jut be zero
  • vrdavebvrdaveb Posts: 1,596 Oculus Staff
    what variable is the speed the player is going at a given movment.
    That's MoveThrottle. You could use something like the following:
    MoveThrottle = Vector3.Scale(MoveThrottle, 1f + JumpForce);

    Disclaimer: I haven't tested this.

  • VRfriend2016XVRfriend2016X Posts: 144
    Hiro Protagonist
    edited July 2016
    Nice thanks so much. Except i get errors because it says the use is   Vector3.Scale( Vector a, Vector b).
    and Jumpforce is not a vector, so should we change something there? On top declaration says Jumpforce is a float
  • vrdavebvrdaveb Posts: 1,596 Oculus Staff
    Try (1f + JumpForce) * MoveThrottle. Unity also has some helpful resources on C# programming:
    1
    2
    3
  • VRfriend2016XVRfriend2016X Posts: 144
    Hiro Protagonist
    edited July 2016
    Thanks yeah. I have lot of videos tutorials and documentation. thanks. Look i'll show you picture what is happening now. By the way the code you said MoveThrottle = (1f + Jumpforce) * MoveThrottle just basicallly lounges the player a little forwards. but it doesn't give him any upward jump.

    ANyways i've tried THIS:
    MoveThrottle =  (1f + JumpForce) * MoveThrottle;
    And that resulted in what i said
    I've also tried this
    MoveThrottle += new Vector3(0, transform.lossyScale.y * JumpForce, 0);

    That gives no forward movement at all.

    AND NOTE i want forward movement based on how fast you walking or running forwards

    Anyways i've tried this

    MoveThrottle += new Vector3(0, transform.lossyScale.y * JumpForce, 0);
    MoveThrottle = (1f + JumpForce) * MoveThrottle;

    That results in just jumpting up and zero forward movement

    and i've tried this;
    MoveThrottle += new Vector3(0,0 , Vector3.z * JumpForce);
    MoveThrottle += new Vector3(0, transform.lossyScale.y * JumpForce, 0);

    No use. No forward movement.
    If there is forward movement. it's tiny even if i push the joystick all the way forward.



  • shan1392shan1392 Posts: 9
    NerveGear
    Hi,

    I hope I'm not too late but I just ran into this problem today and fixed it by removing this from the code (You can find this under UpdateMovement():

    		// No positional movement if we are in the air
    		  if (!Controller.isGrounded)
    		  	MoveScale = 0.0f;
  • VRfriend2016XVRfriend2016X Posts: 144
    Hiro Protagonist
    edited July 2016
    Thanks I'll try it!!!!
  • shan1392shan1392 Posts: 9
    NerveGear
    I said remove that code, not insert.

    In the original script, if the character is not grounded, the Move Scale is set to 0.0f which is why you jump up and come back down without any forward or backward motion. 

    Commenting out those lines of code will give you momentum when you jump.

    Thanks but does that also fix the fact the the jumps are really quick like BAM to the air BAM back down.
    No it does not fix the fact that jumps are very unrealistic. I'm still thinking of a way to fix that.
  • VRfriend2016XVRfriend2016X Posts: 144
    Hiro Protagonist
    thanks for the response. yeah i know what you meant.  I'm also trying tofix it. Tried looking at physics examples of jump done in other games but they usually use RIgidbodies and thats a different way of doing it. the OVR character contrller is not a rigidbody. Also i've tried checking 2D video games of how they do jumps in 2D games but as i am not a good scripter i don't know how to do that either.
  • shan1392shan1392 Posts: 9
    NerveGear
    Alright I have something figured out which seems to be working a lot better.

    In your OVRPlayerController, (might be line 187), look for:
    MoveThrottle.y = (MoveThrottle.y > 0.0f) ? (MoveThrottle.y / motorDamp ) : MoveThrottle.y;
    and change it to:
    MoveThrottle.y = (MoveThrottle.y > 0.0f) ? (MoveThrottle.y / motorDamp * 1.2f) : MoveThrottle.y;
    Next, adjust your Acceleration, Jump Force and Gravity Modifier to improve it as much as you can.

    I'm using Acceleration = 0.25, Jump Force = 0.45 and Gravity Modifier = 0.23

    I'm still playing around with these values to make it as realistic as possible but I think this should give you a good start.
  • VRfriend2016XVRfriend2016X Posts: 144
    Hiro Protagonist
    Thanks Shan. i'll do it!!!
  • VRfriend2016XVRfriend2016X Posts: 144
    Hiro Protagonist
    edited July 2016
    Hey Shan that was pretty good EXCEPT in mine it keep jumping and jumping after it lands. Wonder why. I did some of the tips that people told me(you) before like  remove the
    // No positional movement if we are in the air
    		  if (!Controller.isGrounded)
    		  	MoveScale = 0.0f;

    But yeah currently it's like bouncing. great jumps but bounces endlessly. Also, the jumps are super high

  • VRfriend2016XVRfriend2016X Posts: 144
    Hiro Protagonist
    edited July 2016
    Shan could i show you my code? I don't know why it's bouncing. and i only press the button once. Maybe i'm doing something you're not. i can see it's an excellent jump but just that in my side.....it's bouncing over and over after one press. That doest seem like it's happening to you
«1
Sign In or Register to comment.