Search Unity

How to prevent grabbed objects from physically interacting with player?

Discussion in 'VR' started by Factknowhow, Sep 16, 2018.

  1. Factknowhow

    Factknowhow

    Joined:
    Sep 16, 2018
    Posts:
    2
    I've looked everywhere for answers but search results come back lacking. How do I prevent the player from walking onto an object they've picked up and flying?

    The problem I'm running into is:
    1. I pick up an object using the Grabber.cs and Grabbable.cs scripts on hands and object respectively
    2. Hold it so that it is inside what would be my player model
    3. Walk forward using joystick, sometimes needing to adjust position of object
    4. End up flying straight up

    This is using the default OVR Player and Grabbing scripts. How am I the only person running into this problem?
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    I would imagine that typically, grabbable objects would not be in the same layer as things you can collide with.
     
  3. Factknowhow

    Factknowhow

    Joined:
    Sep 16, 2018
    Posts:
    2
    Is it possible to detect when an object has been picked up? Say, with an overridden OnGrab() method? I'm not seeing anything like that. I would like for the player to be able to physically interact with object normally unless somebody is holding them. Also, thank you for introducing me to layers.

    Edit: Managed it by getting the OVRGrabbable component of the game object and checking the grabbedBy object to see if it was null. If it is null, then switch to physics interacting layer. Otherwise, switch to phasing layer. Don't know if there's a more mainstream way to do it, but it works.
     
    Last edited: Sep 17, 2018
    JoeStrout likes this.
  4. UnbelievableFlavour

    UnbelievableFlavour

    Joined:
    Aug 20, 2019
    Posts:
    4
    For all the people still fighting this problem. My solution was like this:
    Create 3 layers.
    • Player.
    • Level.
    • Grabbables.
    Then go to Project Settings > Physics.
    You will see a lot of checkboxes with layers interacting with each other. Make sure the checkbox where Player collides with grabbables is turned off.

    Now make sure all your level elements are in the 'level' layer.
    Make sure the player is in the 'player' layer.
    And make sure the grabbable game objects are in the 'grabbables' layer.

    For the final touch. To make sure you are actually able to interact with stuff in the grabbables layer. Set your game object where you grab with(gameObject with OVRgrabber) in the 'grabbables' layer.

    This should make sure the grabbables will interact with the level and your hands but not the player! Voila :) Hope this is of help to someone.
     
    unity_sToLfdyT2s_3ww and Corysia like this.
  5. Corysia

    Corysia

    Joined:
    Mar 14, 2018
    Posts:
    108
    Yes, that's the way I solved it, too. I'll be showing that in my example project later today or tomorrow.
     
    JoeStrout likes this.