Example #1
0
    /// <summary>
    /// Apply friction torque.
    /// </summary>
    private void FixedUpdate()
    {
        if (!servo || !rigidbody || !frictionProfile)
        {
            return;
        }

        //Vector 3 used to pass 3D positions and directions (x, y, z)
        //servo.axis is the local coordinates of the object, which is converted to global coordinates
        //multiplying direction of joint action by servo velocity and friction coefficients
        Vector3 frictionTorque = -(transform.TransformDirection(servo.axis)).normalized * (servo.GetServoVelocity() * frictionProfile.viscousK + frictionProfile.staticK);

        rigidbody.AddTorque(frictionTorque);

        if (servo.servoBase)
        {
            servo.servoBase.AddTorque(-frictionTorque);
        }
        if (isDebugging)
        {
            Debug.DrawRay(transform.position, frictionTorque);
        }
    }