How to set the linear offset of physics constraint?

When the physics constraint is created, it creates a “reference frame”, which is the transform from which the linear limits are allowed.

What you can do is have your drawer in the center to set the limits as you would like them to be, but then on begin play, after the constraint is created, you could manually set the drawer to the location that you want it to be in. Provided the constraint isn’t forcing the drawer into a particular location with a position drive, it will stay there.

In my case, I create the physics constraint manually in C++:

PhysicsConstraintComponent->SetConstrainedComponents(BasePrimitiveComponent, NAME_None, ProxyMeshComponent, NAME_None);

My slider is at one end of where it can move (essentially the drawer is in) when the constraint is created.

Then I set the reference frame position to be zero, because the slider is in a relative space of 0 when it’s half way along it’s movement (which would be the location for you where the drawer is half out):

SliderPhysicsConstraintComponent1->SetConstraintReferencePosition(EConstraintFrame::Frame2, FVector::ZeroVector);

Hope that helps and makes some sense.

1 Like