Search Unity

[RESOLVED] Slow rotation if my rigidbody have collider children

Discussion in 'Scripting' started by zenden_1, May 26, 2019.

  1. zenden_1

    zenden_1

    Joined:
    May 20, 2017
    Posts:
    53
    Hi, actually i've this script

    Code (CSharp):
    1. void FirstPersonShipManager()
    2.     {
    3.         //GESTION DES ROTATION\\
    4.         float _RotZ = Input.GetAxis("Horizontal") * LateralRotSensivity * Time.fixedDeltaTime;
    5.  
    6.         Vector3 LateralRot = new Vector3(0, 0, -_RotZ);
    7.         //Rotation AVEC rigidbody
    8.         rb.AddRelativeTorque(LateralRot);
    9.  
    10.         transform.TransformDirection(LateralRot);
    11.  
    12.     }
    Now, if the childrens of my object with rigidbody have collider the rotation become VERY slow.

    It happend when my childrens does no touch the parent.

    Somebody know why ?
     
  2. doctorpangloss

    doctorpangloss

    Joined:
    Feb 20, 2013
    Posts:
    270
    What do you mean, the rotation is slow? Do you mean you expect the object to rotate faster than it does?

    Code (CSharp):
    1. transform.TransformDirection(LateralRot);
    I don't think you want to modify the transform of the rigid body this way.
     
  3. zenden_1

    zenden_1

    Joined:
    May 20, 2017
    Posts:
    53
    Hi, i found the solution during this night and finally i learn collider of children affect mass of parent.

    It's very useful if you want realistic value but if you are in my case you have to do that :

    1) Get the value of you rigidbody without children

    Code (CSharp):
    1.  
    2. print(rb.inertiaTensorRotation);
    3. print(rb.inertiaTensor);
    4. print(rb.centerOfMass);
    2) Edit inertiaTensorRotation - inertiaTensor - centerOfMass

    Set the value you got instead of my value.

    Code (CSharp):
    1. rb.inertiaTensorRotation = new Quaternion(0,0,0,1f);
    2. rb.inertiaTensor = new Vector3(4.2f,4.2f,4.2f);
    3. rb.centerOfMass = Vector3.zero;