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); }
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); }