Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Discussion Hinge Joint bug or simple fix

Discussion in 'Physics' started by riasillo, Sep 23, 2023.

  1. riasillo

    riasillo

    Joined:
    May 23, 2023
    Posts:
    24
    5 hours trying to solve a simple problem, 1 click to fix it. Not sure who needs to hear this but figured I would contribute. I'm total noob so maybe I'm missing something very basic here but solved a problem and figured others might have encountered same.

    Two pinball flippers, code works perfect for 1, the other, flipping in the wrong direction.
    Because limits on hinge joint can't be set with a negative max angle that is a larger number than min.
    which to me makes no sense because you should always be able to talk about negative rotations?

    so even though I had it set in my code, hinge joint component was changing values in limit to same number.
    (took me a while to figure that out, watching the inspector component during play time in prefab edit mode is my new first move now to problem solving).

    Example Left flipper limit set to 0 min, 40 max. wrong direction, flips down. Limt set to min 0, max -40. Get's set on play to -40,-40. because negative 40 is less than 0. set min to -45 and max to 0. it rotates down and flips up to 0. etc. and every other crazy glitch you can imagine trying to fix this with code.

    Right flipper works perfect 0 to 40.
    So i go back to that code for left flipper.
    Try flipping the button actions, and burning an hour on work arounds that don't work etc.

    Then it occurs to me it's upside down.
    maybe flip the joint vectors (even though, I don't really understand why you would have to. )
    change the vector on the connected body axis to -1 from 1. and it worked setting limits 0 to 40.
    And I'm like just punching myself in the face for not thinking of that sooner.

    When dealing with rotations, you should be able to set it to go from a "higher" number to a lower number. Most objects are probably transformed to 0 degrees on import but you can only turn them clockwise.
    Doesn't make sense to me. But hope that helps. Unless there is a better right way to do this.
     
  2. Camobiwon

    Camobiwon

    Joined:
    Dec 7, 2021
    Posts:
    6
    For your other paddle it makes sense that the target is inversed. Think about if you rotated both of them clockwise, they would rotate in seemingly the opposite direction. For me, I would just solve it by doing
    Quaternion.Inverse(targetRotation)
    .
     
    riasillo likes this.
  3. riasillo

    riasillo

    Joined:
    May 23, 2023
    Posts:
    24
    thank you.. I will remember that. Not really familiar with quaternion, have seen it in tutorials and just copied not really understanding... am I still crazy to think the hinge joint should allow you to set it to go from 0 to -40 or 0 to 40 and it would go clockwise or counter?