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

ConfigurableJoint target angular velocity (Unity5)

Discussion in 'Physics' started by Matkins, Mar 7, 2015.

  1. Matkins

    Matkins

    Joined:
    Aug 24, 2009
    Posts:
    152
    Since upgrading my project to Unity5 I'm finding that my configurbleJoints don't respond to a target angular velocity being set. These are working fine in Unity4. Are there any fundamental changes to configurableJoints, or the wider physics engine, that could be causing this? Or is it just a bug that needs fixing in 5?
     
  2. Xoduz

    Xoduz

    Joined:
    Apr 6, 2013
    Posts:
    135
    Maybe it's similar to the issue I have with HingeJoints... if I set the targetPosition of the spring while the joint has "useSpring" set to true, nothing happens. If I set it while it's false, it gets set to true AND the HingeJoint reacts to the new targetPosition. Unfortunately having to set useSpring to false every time I need to update the targetPosition isn't very handy...
     
  3. jaakaappi

    jaakaappi

    Joined:
    Aug 17, 2012
    Posts:
    12
    I know this thread has been here for a while, but it came up when I was looking for a solution for the angular velocity not affecting anything, despite of the angular X motion -settings. The joint started to react to the velocity when I changed the dampening on the angular X motion. I hope this helps :)
     
  4. justaddice83

    justaddice83

    Joined:
    Sep 19, 2012
    Posts:
    44
    Been having the same problem.

    I can see targetAngularVelocity being changed in the editor, but no update on the object. When I change the value in the editor (by just 0.1), then viola it starts moving.

    Can't get the code any simpler than this. Its like a 'dirty flag' needs to be set so that PhysX can react to a change in values.

    using UnityEngine;
    using System.Collections;

    public class TargetAngularVelocity_Test : MonoBehaviour
    {
    public ConfigurableJoint joint;

    void FixedUpdate()
    {
    if( Input.GetKey("q"))
    joint.targetAngularVelocity = new Vector3(-1, 0, 0);

    else if( Input.GetKey("a"))
    joint.targetAngularVelocity = new Vector3(1, 0, 0);
    }
    }
     
    Last edited: Aug 21, 2015
  5. justaddice83

    justaddice83

    Joined:
    Sep 19, 2012
    Posts:
    44
  6. danieldownes

    danieldownes

    Joined:
    Apr 20, 2013
    Posts:
    9
    Also having a problem with targetAngularVelocity.

    Have tried changing the dampening and other parameters too as suggested by jaakaappi.
     
  7. inum76

    inum76

    Joined:
    Apr 26, 2014
    Posts:
    3
    I found while using scrips, C#, The Rigidbody falls asleep. You need to wake it up within the script during each update.
    This is my vid on the subject if you wish to check it out. Link: ConfigurableJointScript 1
    Hope this helps.
     
  8. inum76

    inum76

    Joined:
    Apr 26, 2014
    Posts:
    3
    I found while using scrips, C#, The Rigidbody falls asleep. You need to wake it up within the script during each update.
    This is my vid on the subject if you wish to check it out. Link: ConfigurableJointScript 1
    Hope this helps.
     
  9. dansav

    dansav

    Joined:
    Sep 22, 2005
    Posts:
    492
    I tested this and sent in a demo to unity to explain the problem. The configurableJoint targetAngularVelocity seems to be broken. Waking them up did not seem to help in 5.3.5. If anybody has any workarounds this is holding up my project also.
     
  10. JayLemmon

    JayLemmon

    Joined:
    Jan 8, 2018
    Posts:
    1
    I had this problem. As jaakaappi mentioned, you need to have the damping on the joint set to something non-0. Motors in PhysX seem to work using the damping parameter. In a motorless joint, if the velocity exceeds 0, a force is created based on the damping to push it back to 0. In a motored joint, the velocity difference from the target velocity is used to create the damping force instead. This damping force is the motor force. If the damping is set to 0, you don't get any motor force.

    You need to do something like

    Code (CSharp):
    1. myJoint.angularXDrive = new JointDrive {
    2.     maximumForce = 10,
    3.     positionSpring = 0,
    4.     positionDamper = 1e10f,
    5. };
    You probably want to set the position damper to a very large value and limit the maximumForce. That will tell the motor to correct for the full velocity difference every frame using up to the maximumForce. If you set the maximum force to a large value and set a small damping constant instead the physics engine will constantly be over or under shooting the target velocity.

    From my experiments, it's important that positionDamper * (currentVelocity - targetVelocity) is less than float max, or else the motor will get stuck "on". I chose 1e10 because it's huge compared to any reasonable value but well below float max.