Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Moving hinge joint in a script has no effect

Discussion in 'Editor & General Support' started by zorba, Feb 13, 2010.

  1. zorba

    zorba

    Joined:
    Oct 2, 2009
    Posts:
    56
    I have a kinematic rigid body (body A) that I move in a script forward and backward, along a platform. A separate rigid body is attached to body A with a hinge joint. I can move body A and body B follows as expected.

    however, if I change the anchor of the hinge at runtime, shouldn't the hinged body move along? It does not, and in fact the hinge anchor doesn't seem to have any effect.

    Any ideas on what is going on ?
     
  2. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    Can you describe what should be happening in the game when you move the hinge anchor?
     
  3. zorba

    zorba

    Joined:
    Oct 2, 2009
    Posts:
    56
    Well,

    What I was expecting to happen when let's say, the Y value of the anchor is for the dependent object to lower, now pivoting about the lower anchor point.

    What I am trying to do is in effect simulate lengthening of a pendulum. The hinge joint allows the pendulum to swing, but I want to dynamically lengthen the arm of the pendulum and have different characteristics show up naturally as the arm lengthens.

    I am open to any alternative ways to implement this. One thing that came to mind but haven't had time to try is deleting/re-creating the joint at each time step, but it is a workaround and I try to avoid these, at least early in development.
     
  4. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    I've just checked, and you're right, the anchor point won't change while the game is running. You can probably get the effect you want with a configurable joint, although it's a bit more laborious to set up. Set the joint's X and Z motion to "Locked" and the Y motion to "Limited". Then, set the angular Y and Z motion to "Locked" and the angular X to "Free". If you run the game and then go to the scene view, you'll see the pendulum extend if you vary the limit field of its linear limit. You can also do this in code using the joint's linearLimit property.
     
  5. zorba

    zorba

    Joined:
    Oct 2, 2009
    Posts:
    56
    Ok, that worked; Using a full joint, I can change the limit in the script and the dependent object moves with it. Thanks!

    By the way, it would be nice to have some built-in tools to help visualize the universal joint, it is kind of mess to set up.

    Thanks again.