Search Unity

Is there a way to physically hold one object between two colliders ?

Discussion in 'Physics' started by Mehd, Mar 12, 2019.

  1. Mehd

    Mehd

    Joined:
    Apr 29, 2016
    Posts:
    91
    Hi !

    I was wondering whether anyone knew of a way to physically hold one object between two colliders, in the same you'd hold a book in your hand. In my experiments, if the grip if too tight, the colliders jitter and eventually falls out. However, if the grip isn't really firm, then the object slowly slides out.




    Thanks !
     
  2. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    I dont think holding it with friction is gonna work the way its implemented in most game engine(i assume, i didnt actually help write any, heh)

    Try parenting for stuff like hand holding, you can take advantage of various joints, you can calculate the wanted position and teleport it there or apply a counter force to get him there.

    Many ways to do almost everything, hget to know the tools and let you creativity run wild. ;)
     
  3. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,510
    I'd try using joints in the clamp structure, and always apply forces via joints (motor? spring?). I think this is the only way that the physics system could be aware of the grabbed object and solve the situation accordingly.

    As for the video, it looks like you're applying movements via Transform and/or Rigidbody.MovePosition/MoveRotation. This "forces" the physics objects to be located in specific positions/rotations without any chance to react properly to the situation where a solid object is being grabbed. Using joints in all the involved elements allows the physics engine to be aware of the situation. The joints may then apply more or less force, with the object being held more or less firmly based on the force and the friction.
     
    Mehd likes this.
  4. Mehd

    Mehd

    Joined:
    Apr 29, 2016
    Posts:
    91
    You must be right. After having tried various options based on transforms, I'm gonna go back to joints.

    Thanks for the tips! :)
     
    Edy likes this.