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

hard stop in character joints

Discussion in 'Scripting' started by smarcus, Sep 18, 2007.

  1. smarcus

    smarcus

    Joined:
    Sep 18, 2007
    Posts:
    113
    Hello- forgive me if this has been covered elsewhere; I did a preliminary search in the forums and didn't see anything that seemed to address this. I've been experimenting with the joint system and this is where I am.

    I have a series of spheres (because they are cheap to make) connected like so:

    O-o-o-o

    where O is kinematic and the rest are character jointed onto the sphere to their immediate left. What I want is to be able to have each joint "bend" say, 30°, within the physics engine. So I set it up as follows:

    Code (csharp):
    1. Axis> X=0; Y=1; Z=0
    2. High Twist Limit> Limit=20; Bouncyness,Spring,Damper=0
    I tried giving each of the smaller spheres an Update call such that if space was down they called
    Code (csharp):
    1. rigidbody.SetTorque(0,-50,0);
    This works ok, but they overshoot the High Twist Limit. Similarly, when I move the main sphere around they will swing around backwards (and I would like them to hit a "wall" at 0° rotation and lock into place.

    Is there a better way to do this? Am I even making sense?

    Thanks!

    Also, Hi! I am new!
     
  2. smarcus

    smarcus

    Joined:
    Sep 18, 2007
    Posts:
    113
    No one? I will try and restate the question more simply.

    A->B->C (B has a character joint with A as the target, etc for C). The joins have twist limits of 0 for the time being.

    When I rotate A, the torque does not change B's position much (it changes some) but C is clearly bent beyond the constraints that I thought twist limits imposed (if I increase the chain length, they start wrapping around A). I have tried adding bounciness, extremely high spring values ("infinity" seems to break something)... no go: the limits seem to be just vague suggestions.

    Is there a way to lock the rotation of a joint at a given value without using a fixed joint? These objects essentially form an arm and I don't want the elbow to bend backwards, but I do want to be able to bend it forward within the physics engine...

    thanks!
     
  3. metervara

    metervara

    Joined:
    Jun 15, 2006
    Posts:
    203
    Hi.

    Irc the character joint is not fully implemented. So springs and some other things are not working. If you're just bending in one axis (like an elbow joint) I would use the hinge joint, it works perfectly. Use the target position of the spring to set the angle you want for the joint.

    /Patrik
     
  4. smarcus

    smarcus

    Joined:
    Sep 18, 2007
    Posts:
    113
    Thanks! I will try that instead.
     
  5. smarcus

    smarcus

    Joined:
    Sep 18, 2007
    Posts:
    113
    So the hinge joint works better in general I think, but when I stop applying a torque force and they bounce back, they still overshoot the target I set in the spring settings. Is there a way to make it so:

    1. torque is applied to arm
    2. arm hits 30° rotation and stops (no bouncing or overshooting)
    3. torque application ceases
    4. arm returns to 0° (no bouncing or overshooting)

    I feel like I could do this with transforms rather than the physics model, but I'd like to impart force when the arm hits something.