2
\$\begingroup\$

I am working on a physics driven pressable button, but I cannot seem to tackle the minimum and maximum limits.

This is the rig I have set up for the button (as it looks when pressed down).
2D view: 2D view

3D view: 3D view

The idea is that the box collider is a trigger and the button (cylinder, mesh collider) is a rigidbody with configurable joint, locked and limited on a single axis. I am using configurable joint, as that's the only one that supports basic, linear restrictions.

I have set up the configurable joint to restrict motion on a single axis, but the joint only allows single dimensional limit, that is applied to both directions. Screen capture of relevant configuration: Configuration Joint configuration

Basically, the opened Linear Limit section is the last property that has been changed for the joint - anything else are defaults and irrelevant (at least I haven't found my solution in the properties below, mostly angular stuff).

The limit of 0.2 units work, and the button can be pressed - it only gets pressed until those 0.2 units and thats the expected behaviour.
The unexpected is that sometimes the angle at which I hit the button, adds force to the button outwards from the box, and it moves 0.2 away from it, ending up like this:

The unexpected upper limit

Obviously, the specified limit of 0.2 units constrain the movement in both directions from the anchor, actually resulting in the range of -0.2 to 0.2 (relative to anchor).

How, and is it even possible, to restrict the movement only in a single direction relative to anchor?

\$\endgroup\$
2
\$\begingroup\$

You are correct about the fact that the limit isn't a min-max limit, but rather constraints in both directions. So if your goal is to limit your movement range to 0.2 units, your limit has to be set to 0.1 (-0.1 - 0.1).

For this to work correctly, your initial "button" position has to be centered between the desired min- and max-position.

You can then add an initial force to move the button to its max position or add a Constant Force Component to the button which will push the button outwards. The latter will have the nice effect that the button will move back out once pressed.

\$\endgroup\$
  • \$\begingroup\$ Oh, the Constant Force idea is awesome, though, not always desired. Initial force... is it a Configurable Joint property or should I add a script that will hit the button upon Start()? \$\endgroup\$ – joltmode Dec 31 '15 at 11:37
  • 1
    \$\begingroup\$ @joltmode It's not a property, you'd have to add a script that moves the button to the desired position in Start. \$\endgroup\$ – bummzack Dec 31 '15 at 18:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.