Search Unity

Wobbly button, configurable joint questions

Discussion in 'Physics' started by Innovine, Mar 1, 2018.

  1. Innovine

    Innovine

    Joined:
    Aug 6, 2017
    Posts:
    522
    Hi, I am trying to implement a physics based push-button and have been beating my head against this for a few days now.
    Hopefully someone can spot what I'm doing wrong, or recommend a better way.

    I just want a cube button, which I can push using a spherical rigid body (which is kinematic, attached to my VR hand controller). The other thing is that the button needs to be constrained on its local axis, since it'll be a part of the controls for a moving vehicle.

    I have attached a configurable joint to the button, and set everything but movement on Y to locked. The springs are set to zero, and the limit distance is small. I can nudge the button and it behaves reasonably well, but if i push it from the sides it will rotate a bit and snap back to where it should be, and if I push it in a straight line it'll move way beyond the limit, then start vibrating and eventually snap back to the original position.

    How can I just absolutely lock it to the local Y axis, so that I can push it with the sphere rigid body up to a maximum distance, and then have it stop there (allow the sphere to penetrate is fine). And then when the sphere moves away, have the button return to its starting point ?


    It looks like this: https://i.imgur.com/f5s9KPx.gifv

    This is not really what I'd call Locked.

    My joint configuration:


     
  2. Innovine

    Innovine

    Joined:
    Aug 6, 2017
    Posts:
    522
    Any suggestions? Why doesn't "Locked" prevent the rotations, that seems pretty simple and obvious to me :/
     
  3. Innovine

    Innovine

    Joined:
    Aug 6, 2017
    Posts:
    522
    Bump, due to no answer after a few weeks for what seems like a very basic question.
     
  4. Ultroman

    Ultroman

    Joined:
    Mar 10, 2014
    Posts:
    110
    The Physx joints are soft joints, meaning they can exceed their limits, even when "Locked", and will then try to move back within their limits. It's a "feature". I'm trying to make my character controller pick up objects, but they often jitter and wobble around like crazy, even when all the rigidbodies have the same mass. I've tried everything now.
     
  5. Innovine

    Innovine

    Joined:
    Aug 6, 2017
    Posts:
    522
    Thanks. I don't see even an attempt to lock or limit anything here though. I did not yet try using a joint to attach the pushing collider to the controller, and allowing that joint to wobble (hopefully instead of the button).

    I ended up making my button is-kinematic, and on detecting the controller collision, I note the controllers initial position and in subsequent frames I check to see how it has moved on the buttons push axis, and then move the button manually, and stop this if the limits are reached or the controller moves out of range.

    I did similar for flip switches, only using rotation. There are occasional flickers and jitters which i haven't worked out yet, but the result is a lot better than using physics.
     
  6. Matt-Voda

    Matt-Voda

    Joined:
    May 12, 2016
    Posts:
    3
    Hey Innovine, I'd like to implement your is-kinematic button approach. Any chance you could share the relevant code?
     
  7. enhawk

    enhawk

    Joined:
    Aug 22, 2013
    Posts:
    833
    @Innovine set your connected body to isKinematic and constrain all.
     
  8. Innovine

    Innovine

    Joined:
    Aug 6, 2017
    Posts:
    522
    Isn't that what I'm already doing?
     
  9. enhawk

    enhawk

    Joined:
    Aug 22, 2013
    Posts:
    833
    in your connected body it says "none" (actually you probably don't need to do any constraints, just isKinematic on the connected--pinning?--rigidbody) Currently it is self pinning when set to none. Somehow this works, not sure how, but I had the same problem that lead me to this thread.
     
  10. Innovine

    Innovine

    Joined:
    Aug 6, 2017
    Posts:
    522
    It's been a while since I looked at this, and I don't have the project files as shown for a quick test. By connected and pinning bodies, do you mean I should have the cube connected to a third, new body, which is isKinematic, and the behavior is different from none?
     
  11. enhawk

    enhawk

    Joined:
    Aug 22, 2013
    Posts:
    833
    Where it says connected body, fill that with another empty gameobject that has a rigidbody with isKinematic set to true (and not to use gravity).
     
    Innovine likes this.
  12. Innovine

    Innovine

    Joined:
    Aug 6, 2017
    Posts:
    522
    Understood, will give it a try :)