Example #1
0
    protected virtual void SetJointAnchorPoints(Joint joint, JointConnectionComponent attachmentComponent, Vector3 connectionPoint)
    {
        Vector3 closestPoint = attachmentComponent.GetClosestConnectionPoint(connectionPoint);

        PhysicsComponent physics = attachmentComponent.Physics;

        joint.anchor          = transform.InverseTransformPoint(connectionPoint);
        joint.connectedAnchor = physics.transform.InverseTransformPoint(closestPoint);
    }
Example #2
0
    public void ConnectObject(JointConnectionComponent attachmentComponent, Vector3 connectionPoint)
    {
        GameObject       target        = attachmentComponent.gameObject;
        PhysicsComponent targetPhysics = attachmentComponent.Physics;

        if (connectedGameObjects.Contains(target) || targetPhysics.IsConnectedToJoint)
        {
            return;
        }

        Joint joint = CreateJoint();

        SetJointAnchorPoints(joint, attachmentComponent, connectionPoint);
        OverrideRigidbodySettings(targetPhysics.Rigidbody);
        joint.connectedBody = targetPhysics.Rigidbody;

        RegisterConnectedObject(target, joint, targetPhysics);
    }