How to Jump in VR using Unity's New Input System

SdĂ­let
VloĆŸit
  • čas pƙidĂĄn 4. 07. 2024
  • Do you need a Unity VR tutorial about how to jump? I have you covered!
    Hey, devs! Getting used to Unity's new input system and the new XR Interaction Toolkit has been difficult. Well, I just figured out a way to make all that struggle you've been having disappear in two lines of code! After this tutorial, you can jump and do any other action you could ever want with your VR controllers.
    đŸ“ș Watch Next: ‱ What Do I Need to Beco...
    đŸ„œ Enroll in the (now FREE) VR Creator Academy: skool.com/vrcreatoracademy
    ⌚ Timestamps
    0:00 Like the video!
    1:05 Setup & Settings
    3:49 How to Jump
    11:42 Adding Movement
    15:31 FREE Unity asset soon?
    #vr #jump #unity

Komentáƙe • 165

  • @Nickk888SA
    @Nickk888SA Pƙed 3 lety +24

    If anyone uses SteamVR and have problems with the Height calculation(Rig getting under or above the level, etc.), just don't calculate the center with the collider's Y center value but use the _xrRig.cameraInRigSpaceHeight value devided by 2, it perfectly calculates the height, clamping to min 1 also helps a lot!
    Here's my code:
    void Update()
    {
    var center = _xrRig.cameraInRigSpacePos;
    _collider.height = Mathf.Clamp(_xrRig.cameraInRigSpaceHeight, 1.0f, 3.0f);
    _collider.center = new Vector3(center.x, _collider.height / 2, center.z);
    }

    • @JustinPBarnett
      @JustinPBarnett  Pƙed 3 lety +3

      Thanks so much for finding this Nickk888!

    • @me_in_vr8478
      @me_in_vr8478 Pƙed 3 lety +1

      Great tip Nick! Settled some of my falling through the floor problems. Not using SteamVR, but Oculus Quest/Link and it worked for me.

    • @Nickk888SA
      @Nickk888SA Pƙed 3 lety +1

      @@me_in_vr8478 good to know it also works on other devices! Thanks for the info!

    • @mohammadrazakhan3852
      @mohammadrazakhan3852 Pƙed 3 lety +1

      @@me_in_vr8478 hey my player is also falling from the scene so what should I DO ? WHERE should I paste this code ??

    • @me_in_vr8478
      @me_in_vr8478 Pƙed 3 lety +2

      @@mohammadrazakhan3852 So, I'm using a script I've created to handle movement and jumping and stuff like that. It's my PlayerController.cs and I have the code in the Update method, like so:
      // Update is called once per frame
      void Update()
      {
      var center = xRRig.cameraInRigSpacePos;
      capsuleCollider.height = Mathf.Clamp(xRRig.cameraInRigSpaceHeight, 1.0f, 3.0f);
      capsuleCollider.center = new Vector3(center.x, capsuleCollider.height / 2, center.z);
      }

  • @Joooooooooooosh
    @Joooooooooooosh Pƙed 2 lety +10

    I have 20+ years of programming experience and this is all so confusing to me. Thank you for taking the time to make this very detailed tutorial.

  • @Arashi256
    @Arashi256 Pƙed 2 lety +18

    Your jumping tutorial works fine as long as you're on the ground (ie. Y: 0) but you cannot jump from an elevated position. I set everything in my scene that I could climb up like ramps, platforms and so on to a "Ground" layer and changed your code to use: -
    [SerializeField] private LayerMask whatIsGround;
    [SerializeField] private Transform groundCheckPoint;
    ...
    private bool isGrounded => Physics.OverlapSphere(groundCheckPoint.position, .25f, whatIsGround).Length > 0;
    groundCheckPoint is just an empty child GameObject set to (0,0,0) on the XROrigin. Set whatIsGround to your "ground" layer, and you can jump from any elevation as long as what you're standing on is on the "ground" layer. Hope this helps somebody.

    • @davidsimon9353
      @davidsimon9353 Pƙed rokem +2

      Thanks for the suggestion!... also found if you don't want to create a new layer and assign to objects just set .Length>1. I think the capsule collides with the overlap sphere so setting it >1 accounts for that one collision and any others it finds must be ground or something else. Thanks again!

    • @MrDonovanCerminara
      @MrDonovanCerminara Pƙed rokem +1

      Thanks very much for sharing this. It helped me!

    • @DaRealViso
      @DaRealViso Pƙed rokem

      Thank you!

    • @LowPolyBeans.
      @LowPolyBeans. Pƙed 8 měsĂ­ci

      this helped so much as i am making a spiderman, no, arachnid person, game.

  • @burrgurrman2433
    @burrgurrman2433 Pƙed 2 lety

    You're a lifesaver my guy! I've been freaking out for days on how I can get this to work

  • @termi5666
    @termi5666 Pƙed rokem +7

    The ones using XROrigin instead of XRRig. You have to install another package called "XR Core Utilities".
    Go to Package Manager-> + -> Add package by name -> copy this: com.unity.xr.core-utils
    Then in your script add the namespace: using Unity.XR.CoreUtils;
    And the methodes change a little bit, ex:
    using Unity.XR.CoreUtils;
    ...
    {
    private XROrigin _xrOrigin;
    private CapsuleCollider _capsuleCollider;
    ...
    void Start()
    {
    _xrOrigin = GetComponent();
    }
    void Update()
    {
    var center = _xrOrigin.CameraInOriginSpacePos;
    _capsuleCollider.center = new Vector3(center.x, _capsuleCollider.height / 2, center.z);
    _capsuleCollider.height = Mathf.Clamp(_xrOrigin.CameraInOriginSpaceHeight, 1.4f, 1.8f);
    }
    ....

  • @swannschilling474
    @swannschilling474 Pƙed 2 lety +1

    Man your new space looks awesome, your thumnnais are catchy and your content rocks!! 😁

  • @elsyndur4415
    @elsyndur4415 Pƙed 3 lety +3

    Thanks so much for making this! I was struggling for a couple of days to figure out how to get specific buttons to do things in VR. You wouldn't think it would be that hard, but it was, for me!

    • @JustinPBarnett
      @JustinPBarnett  Pƙed 3 lety +1

      You're so welcome! Yea this VR stuff is a bit complicated at first.

    • @anthonyjackson9194
      @anthonyjackson9194 Pƙed 2 lety

      I realy like the XR interaction toolkit, I think it works well and is pretty easy to understand, BUT it definitely doesnt work once you need to extend it to different buttons on the controllers. This video helps massively thank you

  • @SigmaPhonkBabyGronk
    @SigmaPhonkBabyGronk Pƙed 3 lety +1

    Thank you so much!

  • @Martin-xf8be
    @Martin-xf8be Pƙed 3 lety +1

    Dude, you are absolutely awesome. Thank you very much! I really do hope your Patreon takes off - I hope for many new game tutorials there :)

    • @JustinPBarnett
      @JustinPBarnett  Pƙed 3 lety +1

      Thanks so much! And I hope so too 😅, regardless there's lots more tutorials to come!

  • @JustinPBarnett
    @JustinPBarnett  Pƙed 3 lety +4

    Download the Project (for FREE): www.vrcreators.io/codedownloads

  • @ElPatoEncabronado
    @ElPatoEncabronado Pƙed 2 lety +1

    thanks, I've been looking for a tutorial like this. :)

  • @anthonyparker1589
    @anthonyparker1589 Pƙed 3 lety +5

    Short, sweet, and to the point, will never unsub

    • @JustinPBarnett
      @JustinPBarnett  Pƙed 3 lety +2

      many thanks! 🙏

    • @cleverballoon6535
      @cleverballoon6535 Pƙed 3 lety +2

      Agreed, Valems videos are good but they are tricky for me to follow, this is perfect, functionality plus a good explanation so you learn how Unity works

    • @JustinPBarnett
      @JustinPBarnett  Pƙed 3 lety +2

      @@cleverballoon6535 Appreciate you!!

    • @cleverballoon6535
      @cleverballoon6535 Pƙed 3 lety +1

      @@JustinPBarnett Thanks its awesome to see youtubers who respond to their viewers, I have a small gaming channel and i try to do the same since it means a lot to everyone

    • @JustinPBarnett
      @JustinPBarnett  Pƙed 3 lety +2

      @@cleverballoon6535 sure thing, yea I love interacting with people in the comments. Good luck with your channel!!

  • @zoestraw6444
    @zoestraw6444 Pƙed 3 lety +3

    I consider myself a reasonably competent C# coder, but damn you've really got some moves. My girlfriend (a much better coder than me) was teaching me about lambdas a while ago but I hadn't gotten an opportunity to actually use one until this video. Neat stuff!

    • @JustinPBarnett
      @JustinPBarnett  Pƙed 3 lety +1

      Omg they're WONDERFUL once you get the hang of them. Saves so much time!

  • @devchicken1482
    @devchicken1482 Pƙed 3 lety +4

    Great tutorials! it would be awesome to see a realistic, Boneworks like climbing system. But dont stress yourself out and keep up the very helpful tutorials.

  • @robertoedlin
    @robertoedlin Pƙed 3 lety +1

    Awesome. Thanks for doing this! Although I'm currently working on a non locomotion vr project at the moment but definitely want to know how to jump in vr. I could never get it quite right.

    • @JustinPBarnett
      @JustinPBarnett  Pƙed 3 lety +1

      Sure thing! You'll do a locomotion project eventually I'm sure!

  • @me_in_vr8478
    @me_in_vr8478 Pƙed 3 lety +1

    Great video! Thanks for the tutorials. I actually just finished implementing jump this way, like almost exactly (different application of physics to the Rigidbody by specifying Force.Impulse and having a public float for gravity to mess with) only figured it out one day before you posted. This took lots of looking at outdated guides and reading new unity documentation. I was still working on figuring out the capsule collider thing and your guide saved me some extra time and headaches here. All the VR guides out there are about using the Character Controller or the old input system and didn't quite translate.
    There's still a bunch of stuff for me to work out with using Rigidbody and Player Controller. Collisions are a big one--Using XR Grab Interactables and running into walls that send me falling through the floor! Also was having fun with objects that transform.localScale of my player on collision, with a cooldown coroutine--but when I revert to normal size I'm falling through my ground plain. I'm hoping to avoid just using constraints because there will be things I want to knock me around later, and constraining the Y axis turns off the ability to jump. I think next steps for me is figuring out a way to handle steps/stairs/slopes without a Character Controller. Do you know if you've covered any of these or have any quick tips?

    • @JustinPBarnett
      @JustinPBarnett  Pƙed 3 lety +2

      I don't think I've covered those topics, but 100% will be getting to most if not all of them in the near future!

    • @JustinPBarnett
      @JustinPBarnett  Pƙed 3 lety +1

      Thanks so much for your feedback!!

    • @me_in_vr8478
      @me_in_vr8478 Pƙed 3 lety +1

      @@JustinPBarnett So theres a weird issue with jumping that I'll call the trampoline effect. Each jump is higher than the last. It doesn't matter whether you move or teleport in between or how much time you spend on the ground, the height of each consecutive jump is greater.
      I went back in and cleaned up my code.. Then I just switched to your exact methods even to make sure wasn't just something I'd goofed on in my own trial and error. I thought perhaps the jumpForce variable was being changed, so I did Debug.Log("Jumped with " + jumpForce); but it hasn't changed. the grounded check is working, so I'm not double jumping. The height of each jump just increases.... can you test if you are experiencing the same?

    • @JustinPBarnett
      @JustinPBarnett  Pƙed 3 lety +1

      @@me_in_vr8478 oh huh, I didn't test it enough to see if that would happen. I'll look into it. You can join the discord and chat if you want! discord.gg/6mzMQx5VKk

  • @spotlessapple
    @spotlessapple Pƙed rokem +2

    Great tutorial! Using this setup for my current project, awesome content. I was having issues with the IsGrounded function in the video always registering false for the jump, but after making a small change to it everything began working as expected. This might be due to some specific setup unique to my project, but I'll leave the change down below in case others run into something similar:
    private bool IsGrounded => Physics.Raycast(
    transform.position, Vector3.down, GetComponent().bounds.extents.y + 0.1f
    );

    • @elbodomo8875
      @elbodomo8875 Pƙed rokem +1

      For anyone using Terrain and having trouble, bc the does not recognize it. Try using this (transform.position +new Vector3(0,0.1f,0)) position for the ray cast and make the ray 0.2f long

  • @Dustyflyguy
    @Dustyflyguy Pƙed 3 lety +1

    thanks :D

  • @EricPeters
    @EricPeters Pƙed 3 lety +1

    Great tutorial. As always :)
    And if you are looking for a new tutorial idea: How about a 3rd person controller? Similar to MOSS or ASTRO BOT ...

    • @JustinPBarnett
      @JustinPBarnett  Pƙed 3 lety +2

      Thanks! And cool idea! I'd love to give that a shot!

  • @zoestraw6444
    @zoestraw6444 Pƙed 3 lety +2

    Now that Air Link is out developing with Quest 2 as your in-editor test headset is actually super easy, it's great! You just have Air Link up and can run and quit the game as easily as you would with the Rift S, big fan. I don't think that it's quite as smooth as Virtual Desktop was for actually *playing* games wirelessly, but as a development unit I'm having a much easier time with it.

    • @JustinPBarnett
      @JustinPBarnett  Pƙed 3 lety +1

      Absolutely! Air Link is a game changer. (especially when I need to use my long USB-C cable to charge my light while I'm filming instead of having it plugged into the Quest 2 😅)

  • @Arashi256
    @Arashi256 Pƙed 2 lety +5

    I was using a character controller component attached to my XROrigin, but I changed it to rigidbody/capsule collider in order to do this tutorial. But one issue is that when hitting an obstacle with the XROrigin with a character controller component, my XROrigin would just stop - but when hitting an obstacle with a rigidbody/capsule collider, my XROrigin "stutters" against the obstacle rather than just stopping. Is there a fix?

    • @nilayg6807
      @nilayg6807 Pƙed 2 měsĂ­ci

      I'm facing this issue to, lmk if you found a solution please
      This is a physics based jump movement, alot of Unity forum is divided in how it's done and most agree it's best for the user to not do so. Using the Character Controller has been great, I am actively looking for a solution that leverages it

  • @jeffleclerc2904
    @jeffleclerc2904 Pƙed 2 lety +3

    Again, another great tutorial. I'm using Unity 2020.3.29 and XR Rig is deprecated and it's now called XR Origin. I first started following your tutorial knowing I should switch all these Rig for Origin but towards the end, I had _collider underlined and couldn't fix it. So I thought to just change the name of my Origin in Unity and switch my code to Rig to follow yours but Visual Studio told me I couldn't do that. Now i'm stuck not being able to adjust the height of the capsule collider. The first part worked, I could jump. I also decided not to use some lines to allow pressing the A button many times and just fly. That's exactly what I wanted. But the height part is pretty cool and I'd really like to get it working.

    • @JustinPBarnett
      @JustinPBarnett  Pƙed 2 lety +1

      There are some scripts you'll have to rename in order to update from xrrig to xrorigin. And the name of the variable for camera height is different now

  • @ProdigiaGames
    @ProdigiaGames Pƙed 3 lety +1

    I was just looking into this and suddenly this tutorial appears, giving me all the information I didn't know I needed...GET OUT OF MY HEAD đŸ€Ł

  • @TheEnchantedPickaxeHDGaming
    @TheEnchantedPickaxeHDGaming Pƙed 5 měsĂ­ci

    Great tutorial! My only problem right now is maintaining momentum and control mid-air is there something I can add to the existing script to fix this?

  • @AdamCheong
    @AdamCheong Pƙed 3 lety +1

    RE: Character controller following camera in roomscale. This way seems nicer than overriding the CharacterControllerDriver in one of your previous videos.

    • @JustinPBarnett
      @JustinPBarnett  Pƙed 3 lety +1

      Totally agree! I'm getting better as I learn too!

  • @DassVeryGood
    @DassVeryGood Pƙed 2 lety +2

    HAHAHA I picked up the tablet from your last tutorial and since both the tablet and the player capsule have rigid bodys, I was shot out of the scene at 100 mph! Still great video keep it up!

  • @tymcfie3154
    @tymcfie3154 Pƙed 3 lety +1

    your next video should explain how to set up hand tracking. For example something that can be used with the quest

    • @JustinPBarnett
      @JustinPBarnett  Pƙed 3 lety +1

      Definitely gonna try to do that pretty soon now that I’ve got the quest 2!

  • @alex_advanced
    @alex_advanced Pƙed rokem +1

    Hi Justin, great video! One question: Does the new Input System require using the OpenXR backend? Or can I use it just fine with the Oculus plug-in?
    I ask because Unity docs say that the Oculus Integration package isn't compatible with OpenXR at this time, but I do want to use the new Input System
    Thank you!!

  • @AzureWings_
    @AzureWings_ Pƙed 2 lety

    for the movement, how can i change the speed? I kind of want a faster paced game but a sprint button could work too. Also this tutorial worked on 2021.3!

  • @loukenart
    @loukenart Pƙed 3 lety +1

    nice video Justin! i actually own a quest 2, so im exited to see what you will make with it in the future! is there a way to test the game on rift (wich i also have) and then build it on to quest 2? Greetings from Edvard

    • @JustinPBarnett
      @JustinPBarnett  Pƙed 3 lety +2

      Yes! You'll have to use the settings in this video to test on rift and then in the next (or one after?) video I'll post about how to build for the quest

  • @Jamie_Howes
    @Jamie_Howes Pƙed 3 lety +3

    Hey, any chance you make a tutorial on how to make accounts and a login screen when you start up the game. Also if possible could you make a tutorial on how to make a admin panel for only people you give it to (part of the account system kinda)

  • @nocoreal
    @nocoreal Pƙed 5 měsĂ­ci

    Update function gives me this Error: NullReferenceException: Object reference not set to an instance of an object
    have i done something wrong

  • @Nuckl3ar
    @Nuckl3ar Pƙed 3 lety +1

    Have you tried implementing jump mechanics only relying on the Character Controller instead of adding a rigid body on top of it? My main problem is keeping momentum while jumping

    • @JustinPBarnett
      @JustinPBarnett  Pƙed 2 lety

      Personally, I like to keep as much stuff physics-based as I can in my games

  • @cammcream193
    @cammcream193 Pƙed 3 lety

    Awesome tutorial! Loved it but when jumping the scene goes all jittery (jumping and falling) know a fix?

    • @JustinPBarnett
      @JustinPBarnett  Pƙed 2 lety

      Join the discord if you're still having issues and we can help you troubleshoot!

  • @SwamySwank
    @SwamySwank Pƙed 2 lety

    When i did the update code you did to update the collider i went throught the wall when my camera went through it, do you know a fix, im using 2021.3.4f1

  • @smalrebelion
    @smalrebelion Pƙed 2 lety

    I've been trying to implement flight in XR toolkit for a couple days now (I'm a noob). This got me more than halfway there (I just didn't add any of the raycaster stuff so I can jump in the air). Can you make a video like this where you explain how to replace "Vector3.up" with a vector3 of your controllers orientation? Maybe also how to put the force in a while loop?

    • @smalrebelion
      @smalrebelion Pƙed 2 lety

      Scratch that. I found your swimming tutorial and implemented the reference to the camera direction as the force direction. Next step will be to make an option to increase all acceleration vector components orthogonal to the current direction of travel by a specific factor to make turning more responsive and maybe throttle the acceleration based on trigger pull extent. It's pretty rough but for anyone interested it's here:
      github.com/pdettinger/Unity-XR-Interaction-Toolkit/blob/main/PlayerFlight.cs
      using System.Collections;
      using System.Collections.Generic;
      using UnityEngine;
      using UnityEngine.InputSystem;
      [RequireComponent(typeof(Rigidbody))]
      public class PlayerFlight2 : MonoBehaviour
      {
      [SerializeField] InputActionReference FlyActionReference; // Set to XRI righthand/fly
      [SerializeField] InputActionReference AirbreakActionReference; // Set to XRI righthand/Airbreak
      [SerializeField] Transform TrackingReference; // Drag Your hand gameobject into this field
      [SerializeField] float FlyForce = 50.0f;
      [SerializeField] float AirbreakFactor = 5.0f;
      Rigidbody _body;
      Vector3 TurnVector;
      void Awake()
      {
      _body = GetComponent();
      _body.constraints = RigidbodyConstraints.FreezeRotation;
      }
      void FixedUpdate()
      {
      if (FlyActionReference.action.IsPressed())
      {
      Vector3 worldRotation = TrackingReference.TransformDirection(Vector3.forward);
      _body.AddForce(worldRotation * FlyForce, ForceMode.Acceleration);
      }
      if (!FlyActionReference.action.IsPressed() && AirbreakActionReference.action.IsPressed())
      {
      Vector3 crrntVelocity = _body.velocity;
      _body.AddForce(crrntVelocity * -1 * AirbreakFactor, ForceMode.Acceleration);
      }
      }
      }

  • @zima2352
    @zima2352 Pƙed rokem

    Hey Barnett, I had issues with the coding, for example tryping in serializedfield etc didn't pop up along with the majority of coding you where typing.
    I set-up/installed my Unity and VS coding program via another vr channels set-up tutorials (been hoping around leaning).
    Since everything is moving super quick with versions of these programs would it be possible to point me in the direction of the video you have for XR set-up?
    Can't imagine how hard must be to stay ontop of all the updates and versions coming out changing the terminology and ui of all the programs. Videos from 2 years ago you can easily see the mass amount of content updates

  • @kamsin007
    @kamsin007 Pƙed 2 lety

    Great Tutorial. Can you please do a Tutorial for Google Cardboard in version 2021.2 Beta. Thanks :)

    • @JustinPBarnett
      @JustinPBarnett  Pƙed 2 lety

      Ehhhh doubt it 😬 Google cardboard is getting phased out

  • @termi5666
    @termi5666 Pƙed rokem

    I had a problem, and is that when playing it on the editor It worked just fine. But when building the game and playing it (the apk file), some actions didn't work.
    I was doing the tutorial with another action, for example: Click the Joystick. At first, I used the default action called and it worked on the editor play mode but not the build. Then I added another binding for my specific controller (Quest2) called and worked perfectly!!!

  • @IcyStoneGaming
    @IcyStoneGaming Pƙed rokem

    Is this the same with 2021 install

  • @WebHead45.
    @WebHead45. Pƙed 2 lety

    Hi i followed your video for the jump and now when i play my game i fly in the sky without pressing any buttons

  • @mathiolia5877
    @mathiolia5877 Pƙed rokem

    Hi i want to make a Multiplayer setup , not locally, but globally using the Photon, so how can i do that ? my requirement is one person uses PC and one Person uses Quest, how to do that, Mock HMD Maybe? pl advice and guide

  • @ThymeSoup
    @ThymeSoup Pƙed 2 lety +1

    How does the event system work for cases like the joysticks where you need some axis data? I want to do a custom character controller since the provided one does not work well with other physics. The subscribed function does have information about what called it however I don't see a way to get the joystick data from there. And once we have that joystick value, how can we keep track of the orientation of the camera? I noticed that nothing changes in the editor when I move my head.

    • @JustinPBarnett
      @JustinPBarnett  Pƙed 2 lety

      All you need is to read the Vector2 or Vector3 value once that action is performed using value = reference.action.ReadValue();

    • @ThymeSoup
      @ThymeSoup Pƙed 2 lety

      @@JustinPBarnett Yep, that works, thank you. I was confused on how to get camera orientation but I guess the main camera does rotate but it won't show its rotation changing in the editor when running.

  • @windy144
    @windy144 Pƙed rokem

    Hi, so when I do this there is no rig there's only XR ORIGIN (the closest thing) and the console says there are 9 errors.
    I'm not sure because my code matched up BUT none of the precoded presets aren't there so I had to manually type all of it. Can you help?
    My code:
    using UnityEngine;
    using UnityEngine.InputSystem;
    [RequireComponent(typeof(Rigidbody))]
    public class playercontroler : MonoBehaviour
    {
    [SerializeField] private InputActionReference jumpActionReference
    [SerializeField] private jumpForce = 500.0f;

    private Rigidbody _body;
    private bool IsGrounded => Physics.Raycast(
    new Vector2(transform.position.x, transform.position y + 2.0f),
    Vector3.down, 2.0f);
    void Start()
    {
    _body = GetComponent();
    jumpActionReference.action.performed += OnJump;
    }
    void Update()
    {

    }
    private void OnJump(InputAction.CallbackContext obj)
    {
    if (!IsGrounded) return;
    _body.AddForce(Vector3.up * jumpforce);
    }
    }

  • @rasmushenkel4444
    @rasmushenkel4444 Pƙed 2 lety +1

    Hey. Great video! I've got the jump to work, but for some reason the raycast returns false if i'm standing on anything but a plane. I would like to be able to jump from a box collider... What am i doing wrong? Thanks

    • @JustinPBarnett
      @JustinPBarnett  Pƙed 2 lety

      Maybe try extending the raycast a bit more or making sure the other ground objects are being recognized in the raycast layermask

  • @thameesmohamed3582
    @thameesmohamed3582 Pƙed rokem

    bro in unity i can't see that file that name was XRI LeftHand/jump ,kindly help me bro

  • @SigmaPhonkBabyGronk
    @SigmaPhonkBabyGronk Pƙed 3 lety +1

    Hey this tutorial is amazing but i have one problem. every time i jump and turn (with my joystick) , it crashes my game. do you know whats causing that? thanks!

  • @connorgibson3933
    @connorgibson3933 Pƙed 3 lety +1

    having this issue when I press play where it doesn't play on my Oculus Quest 1 headset and takes in no input. However, when I go back to the oculus sdk in the plugin manager everything works fine. Anyone found any solutions for this. also working on a laptop
    Found a half fix for unity editor where I change the OpenXR runtime in project settings but that only makes it work in the editor.

    • @JustinPBarnett
      @JustinPBarnett  Pƙed 3 lety +1

      I'm actually posting a video on Wednesday about how to build and test to the Quest!

  • @asdasdaqwewq9880
    @asdasdaqwewq9880 Pƙed 2 lety +1

    I did everything you do in the video but I go through walls so collision is not working properly (I tried to set it to Continuous) What should I do?

    • @JustinPBarnett
      @JustinPBarnett  Pƙed 2 lety

      Join the discord and we can help you troubleshoot!

  • @keremaslan1988
    @keremaslan1988 Pƙed 2 lety +1

    Hey, I want to move with my left joystick of my Oculus. How can I set it on Input actions menu?

  • @SeanKennedy100
    @SeanKennedy100 Pƙed 2 lety +2

    This doesnt work. I've run through it multiple times now. Sadly doesnt work anymore idk why.

    • @JustinPBarnett
      @JustinPBarnett  Pƙed 2 lety

      Join the discord and we can help you troubleshoot!

  • @hulkmunkeysmashdaily8620
    @hulkmunkeysmashdaily8620 Pƙed 2 lety +1

    Hey Justin great vid. I am trying to add a jump function to my VR game but I get an error that says ‘CS0246; the type name space XRRig could not be found
’ does this mean XRRig is no longer being used in unity? Sorry I’m a super noob.

    • @JustinPBarnett
      @JustinPBarnett  Pƙed 2 lety

      Oh they updated it to “XROrigin”, try that one!

  • @JonTopping
    @JonTopping Pƙed 2 lety +1

    Super helpful! And that trick at 10:00 was awesome, didn't know that, and I'll definitely be using it from now on.
    I had a few issues if you don't mind helping me out.
    1. Biggest one, at 13:08, there's no such thing as an XRRig for my coding, it's giving me an error. Did they change the term recently?
    2. When I do the raycast grounded check, it works when I'm on a regular plane, but it doesn't work when I walk up a hill with a mesh collider. The mesh collider works great, and I walk up the hill fine, but I can't jump, because it's not returning the bool IsGrounded correctly or something.
    3. Lots of VR games have up on the right stick work as jump. How would you set the button to that? I don't see anything in the list that looks like it could be that. Furthermore, what if I want left/right on the right stick to rotate, BUT if you're holding grab, then I want it to do something else (like switch equipped weapon)?
    4. Also, when I move having the capsule collider working (got that working btw!) if I walk into stuff, I get huge jittering. It's like it's trying to move into it, but being pushed back, every update. It's terrible, lol. How do you fix that?
    5. I'm also getting the jittering issue when I jump, where as I fly through the air everything jitters. I turned on interpolation with rigidbody, and that helped, but only if I'm only jumping, the moment I move while jumping it ruins the jump really badly, jittering, and even making me not jump as high. Extrapolate works better, but still jittery, and for some reason the wall issue is now so bad that I can jitter through walls if I keep pushing it.
    6. It looks like this whole action input system is great, as you said, for having multiple types of input work with the same code (so VR, gamepad, keyboard, all with just saying "jump"). How would you set up all the other parts of having jump work with the other inputs?
    7. Now that I have a capsule collider on my character, if I grab that little box, it absolutely freaks out the capsule collider, and I go flying around the world crazily. How do you make objects you grab not interact with your personal collider?

    • @JustinPBarnett
      @JustinPBarnett  Pƙed 2 lety

      Join the Discord and we can help you out with your questions!

    • @tacticalmythic7945
      @tacticalmythic7945 Pƙed 2 lety

      I am getting the same jittery when I jump and use continuous turn script. I asked in Discord, but no one is responding after days of it being in the dev help page
      :(

  • @guilhermedumatrindade4694
    @guilhermedumatrindade4694 Pƙed 2 lety +1

    Hey Justin, how are ya?
    So, I was taking a look at the inputsystem docs and I couldnt really grasp a solution to this
 I created a MaxForce float and wanted to gradually addforce while the button press is true and the force added since the first press is smaller or equal to the max force, but I’m not sure that’s doable with the inputsystem you used in this tutorial? I’m not really proficient in C# yet so this might be easier to implement than I’m imagining.

    • @guilhermedumatrindade4694
      @guilhermedumatrindade4694 Pƙed 2 lety +1

      Basically a jedi jump, the longer you hold, higher it goes

    • @JustinPBarnett
      @JustinPBarnett  Pƙed 2 lety +1

      For that you'd probably have to check in the update method every frame if the button is being pressed. If so, just increase the force a little bit.

  • @arfiandi3998
    @arfiandi3998 Pƙed 2 lety +1

    I used to make handcontroller from your tutorial, then I combined it with this script so I could get jump and hand controller but the rigidbodies made me move so fast, how to fix it ? thank you

    • @JustinPBarnett
      @JustinPBarnett  Pƙed 2 lety +1

      Join the discord and we can help you troubleshoot!

  • @Didrik84
    @Didrik84 Pƙed 2 lety +2

    hi i have tried to make my vr player jump for 11 houers and i cant get it to work can anyone help me

  • @kirbymybae
    @kirbymybae Pƙed 2 lety +2

    The player controller script just has the script in it. I rechecked the code and I dont think our languages match if that can even happen. Can you help me out?

    • @JustinPBarnett
      @JustinPBarnett  Pƙed 2 lety

      What language are you using?? Unity only uses C#

  • @IfionfomyYojin
    @IfionfomyYojin Pƙed 2 lety +1

    In my case the code only works if I add jumpActionReference.asset.Enable(); into the PlayerController.Start method. For reference: Unity 2020.3.19f1, Input System: 1.0.2

  • @eyalretter2354
    @eyalretter2354 Pƙed 2 lety +1

    Hi Justin,
    Thank you very much for these videos. I am watching them and learn.
    How do I clean unity project ?
    I tried this tutorial. It didn't work. Every time I start my project I jump out of the project scene plane (ground). I couldn't fix this.
    I tried to revert and remove:
    I deleted the PlayerControl component, the XR jump interaction we add (and saved), rebuilt => still jumping out on startup.
    I deleted the *.cs file we wrote => still jumping out.
    cleaned the project cache (edit->properties cache) => doesn't work.
    Only deleting the Rigidbody and CapsuleColider I managed to get reid of the jump.
    I am building Android for my Oculus, Where are all the object files being saved?
    Why couldn't I clean this ?
    thanks
    Eyal

    • @JustinPBarnett
      @JustinPBarnett  Pƙed 2 lety +1

      Join the discord if you're still having issues and we can help you troubleshoot!

  • @saradotterer2629
    @saradotterer2629 Pƙed rokem +1

    For quest 1, How do I adjust the following code for jumping in unity version 2021.3.10f1 with the following four errors?
    Code:
    using UnityEngine;
    using UnityEngine.InputSystem;
    using UnityEngine.XR.Interaction.Toolkit;
    [RequireComponent(typeof(Rigidbody))]
    public class PlayerController : MonoBehaviour
    {
    [SerializeField] private InputActionReference jumpActionReference;
    [SerializeField] private float jumpForce = 500.0f;
    private XRRig _xrRig;
    private CapsuleCollider _collider;
    private Rigidbody _body;
    private bool IsGrounded => Physics.Raycast(
    new Vector2(transform.position.x, transform.position.y + 2.0f),
    Vector3.down, 2.0f);
    void Start()
    {
    _xrRig = GetComponent();
    _collider = GetComponent();
    _body = GetComponent();
    jumpActionReference.action.performed += OnJump;
    }
    void Update()
    {
    var center = _xrRig.cameraInRigSpacePos;
    _collider.center = new Vector3(center.x, _collider.center.y, center.z);
    _collider.height = _xrRig.cameraInRigSpaceHeight;
    }
    private void OnJump(InputAction.CallbackContext obj)
    {
    if (!IsGrounded) return;
    _body.AddForce(Vector3.up * jumpForce);
    }
    Four errors received from using the above code:
    Assets\playercontroller1.cs(11,13): warning CS0618: ‘XRRig’ is obsolete: ‘XRRig has been deprecated. Use the XROrigin component instead.’
    Assets\playercontroller1.cs(21,31): warning CS0618: ‘XRRig’ is obsolete: ‘XRRig has been deprecated. Use the XROrigin component instead.’
    Assets\playercontroller1.cs(29,22): warning CS0618: ‘XRRig.cameraInRigSpacePos’ is obsolete: ‘cameraInRigSpacePos has been deprecated. Use the CameraInOriginSpacePos instead.’
    Assets\playercontroller1.cs(31,28): warning CS0618: ‘XRRig.cameraInRigSpaceHeight’ is obsolete: ‘cameraInRigSpaceHeight has been deprecated. Use the CameraInOriginSpaceHeight instead.’

  • @TylerHasCoolFriends
    @TylerHasCoolFriends Pƙed 2 lety

    I am only able to jump once but then I can't jump again. I put a debug log on the code to see in console if it's working and it is, it's saying I jumped every time I press the button but nothing is happening. Anyone able to help?

    • @TylerHasCoolFriends
      @TylerHasCoolFriends Pƙed 2 lety

      Now there's nothing happening at all. Not even in the debug log and I started from scratch and followed the tutorial from the start.

  • @ultimav3868
    @ultimav3868 Pƙed rokem +1

    Can you put the code in the description?

    • @JustinPBarnett
      @JustinPBarnett  Pƙed rokem

      There's a link in the description you have get it at!

  • @InTheMindOfficial
    @InTheMindOfficial Pƙed rokem +1

    I will literally pay for you to help me with my project at this point tbh

    • @JustinPBarnett
      @JustinPBarnett  Pƙed rokem

      You can download the code for the project to get it working!

  • @vjyochee
    @vjyochee Pƙed 2 lety +2

    if we leave away the variable "IsGrounded", this script could be used for flying?

    • @JustinPBarnett
      @JustinPBarnett  Pƙed 2 lety

      you could jump infinite times!! so yea! lol

    • @vjyochee
      @vjyochee Pƙed 2 lety

      @@JustinPBarnett wellwell, some kind of "fly to where HMD is looking at" feature would be cool. maybe in one of the next tutorials? Btw. really good tutorials, great to follow along!

  • @kamuisw
    @kamuisw Pƙed 3 lety +1

    what IDLE are you using?

  • @SawTheAnoy
    @SawTheAnoy Pƙed rokem

    can u just add the script in the desription in typed it and it didnt work

  • @shimong1238
    @shimong1238 Pƙed 2 lety

    I don't know why but it just doesn't work for me
    If I press A on my oculus quest 2 controller nothing happen
    It's the same thing for my animation. If I press the grip button it close my hand but not how I want it and if I press the trigger button, nothing happen );

    • @elbodomo8875
      @elbodomo8875 Pƙed rokem

      hey buddy, for some reason it is bugged, so you have to set a specific action for the oculus touch controller where you did set the xr controller action

  • @canadamanvr3345
    @canadamanvr3345 Pƙed 2 lety +2

    My code just doesn't work, I've tried every way I need help
    Maybe sending the code (I cant pay for patreon due to card being suspended)

    • @JustinPBarnett
      @JustinPBarnett  Pƙed 2 lety

      Join the discord and we can help you troubleshoot!

  • @doomythedubstepfan
    @doomythedubstepfan Pƙed 2 lety +1

    hi my unity console keep getting an error (NullReferenceException: Object reference not set to an instance of an object) CS:32
    My code
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.InputSystem;
    using UnityEngine.XR.Interaction.Toolkit;
    [RequireComponent(typeof(Rigidbody))]
    [RequireComponent(typeof(CapsuleCollider))]
    public class XRPlayerController : MonoBehaviour
    {
    [SerializeField] private InputActionReference JumpActionReference;
    [SerializeField] private float JumpForce = 500.0f;
    private Rigidbody _body;
    private XRRig _xrRig;
    private CapsuleCollider _collider;
    private bool IsGrounded => Physics.Raycast(
    new Vector2(transform.position.x, transform.position.y + 2.0f), Vector3.down, 2.0f);
    void Start()
    {
    _body = GetComponent();
    _collider = GetComponent();
    _xrRig = GetComponent();
    JumpActionReference.action.performed += OnJump;
    }
    void Update()
    {
    var center = _xrRig.cameraInRigSpacePos;
    _collider.height = Mathf.Clamp(_xrRig.cameraInRigSpaceHeight, 1.0f, 3.0f);
    _collider.center = new Vector3(center.x, _collider.height / 2, center.z);
    }
    private void OnJump(InputAction.CallbackContext obj)
    {
    if (!IsGrounded) return;
    _body.AddForce(Vector3.up * JumpForce);
    }
    }

    • @JustinPBarnett
      @JustinPBarnett  Pƙed 2 lety

      Join the discord and we can help you troubleshoot!

  • @InTheMindOfficial
    @InTheMindOfficial Pƙed rokem

    Sadly did not work at all for me, not sure what I'm doing wrong

  • @loeweguckmal
    @loeweguckmal Pƙed 2 lety

    What programm are you using to edit your code? I have problems with mine.

  • @lint_animations4372
    @lint_animations4372 Pƙed 3 lety +2

    I have a problem with grabbing objects, when i grab them they act like a jet pack and psh me in the opposite direction

    • @JustinPBarnett
      @JustinPBarnett  Pƙed 3 lety +2

      Try checking out my physics grab tutorial! The default xr interaction grab doesn't really work too well

    • @lint_animations4372
      @lint_animations4372 Pƙed 3 lety +2

      @@JustinPBarnett thankyou sooo much i really thought you would never reply!

    • @WhoopyStick
      @WhoopyStick Pƙed 2 lety +1

      @@lint_animations4372 I was also experiencing this, I think its because both you and the object have a rigidbody. I actually dialed in the radius of my capsulecollider and made myself "skinnier" then it only happened if I brought the object close to my chest/body.

    • @pegsGamesVR
      @pegsGamesVR Pƙed 2 lety +2

      You will need to set your XR-Rig and other grabbable objects into their own separate layers. (upper right in the inspector, make new layers if non set) Then in edit->Project settings->Physics. Scroll down and uncheck the boxes where the XR-Rig/Grabbable check boxes (Whatever you call them) meet. This should mean they don't collide with each others, while still colliding with everything else.

    • @MuerteRico
      @MuerteRico Pƙed 2 lety

      @@pegsGamesVR I have the same issue. Tried everything - not working. I'm still flying away while grab and object :(

  • @silverwolf5603
    @silverwolf5603 Pƙed 2 lety +1

    I wrote the code the exact same way you did, but an error popped up and say that it couldn't find "XRRig". Any ideas on how I can fix this?

    • @JustinPBarnett
      @JustinPBarnett  Pƙed 2 lety

      Sounds like you missed setting the XRRig either in your inspector or the start method

    • @jbg0801
      @jbg0801 Pƙed 2 lety +2

      if you're still having this issue, you may notice that when he added the reference to the XR rig, it added at the top "using UnityEngine.XR.Interaction.Toolkit;" which he didn't seem to notice/mention. If you add that, it'll be fine.

    • @WhoopyStick
      @WhoopyStick Pƙed 2 lety +2

      I just fixed this same problem. When you start typing in XRRig there will be a green plus sign, when you click it there's a dropdown menu with the XRRig in it. I was about to sell my PC and move to Alaska. Hope this helps.

    • @tacticalmythic7945
      @tacticalmythic7945 Pƙed 2 lety

      @@jbg0801 umm no its now called XrOrigin instead of XrRig

    • @jbg0801
      @jbg0801 Pƙed 2 lety

      @@tacticalmythic7945 if that's changed in the FIVE MONTHS since I wrote that message, so be it

  • @damian3k
    @damian3k Pƙed 2 lety

    _collider.center = new Vector3(center.x, _xrRig.cameraInRigSpaceHeight / 2, center.z); works better ;D

  • @therecbros9840
    @therecbros9840 Pƙed 2 lety

    at 12:26 he looks high
    Only if you pause it

  • @olivername
    @olivername Pƙed rokem

    hey I have defualt inputs only some are there do I need to add all the ones you got @Jusrtin P Barnett