Esempio n. 1
0
    /// <summary>
    /// 连接关节
    /// </summary>
    /// <param name="jointObject">可配置关节</param>
    /// <param name="desiredObject">关节对象</param>
    /// <param name="offset">偏移</param>
    /// <param name="desiredRotation">想要旋转的角度</param>
    /// <returns>可配置关节</returns>
    public static ConfigurableJoint JointToConnect(GameObject jointObject, Rigidbody desiredObject, Vector3 offset, Quaternion desiredRotation)
    {
        ViveGrip_Grabbable grabbable = desiredObject.gameObject.GetComponent <ViveGrip_Grabbable>();
        ConfigurableJoint  joint     = jointObject.AddComponent <ConfigurableJoint>();

        ViveGrip_JointFactory.SetLinearDrive(joint, desiredObject.mass);
        ViveGrip_JointFactory.ConfigureAnchor(joint, offset, grabbable.applyGripRotation);
        if (grabbable.applyGripRotation)
        {
            ViveGrip_JointFactory.SetAngularDrive(joint, desiredObject.mass);
        }
        joint.targetRotation = desiredRotation;
        joint.connectedBody  = desiredObject;
        return(joint);
    }
Esempio n. 2
0
    public static ConfigurableJoint JointToConnect(GameObject jointObject, Rigidbody desiredObject, Quaternion controllerRotation)
    {
        ViveGrip_Grabbable grabbable = desiredObject.gameObject.GetComponent <ViveGrip_Grabbable>();
        ConfigurableJoint  joint     = jointObject.AddComponent <ConfigurableJoint>();

        ViveGrip_JointFactory.SetLinearDrive(joint, desiredObject.mass);
        if (grabbable.anchor.enabled)
        {
            ViveGrip_JointFactory.SetAnchor(joint, desiredObject, grabbable.RotatedAnchor());
        }
        if (grabbable.ApplyGripRotation())
        {
            ViveGrip_JointFactory.SetAngularDrive(joint, desiredObject.mass);
        }
        if (grabbable.SnapToOrientation())
        {
            ViveGrip_JointFactory.SetTargetRotation(joint, desiredObject, grabbable.rotation.localOrientation, controllerRotation);
        }
        joint.connectedBody = desiredObject;
        return(joint);
    }