How to set the linear offset of physics constraint?

I want to create desk with drawer in my game, but I have problem with the Physics Constraint. The physics constraint has parameter only for linear limit, but no for linear offset, which is strange, because there is parameter for angular offset. Now when I put linear limit 50, the drawer can move 25 cm inside the desk and 25 cm outside because the center is in the middle of the drawer. How to change the offset? I don’t want to put all my drawers half open to have normal movement

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

Thank you! this worked