I’m trying to implement ‘lever’ into my android game, here’s image showing what do I want, showing how does it work:
1)

2)

I managed to do basic of it by using joint:
final RevoluteJointDef revoluteJointDef = new RevoluteJointDef();
revoluteJointDef.initialize(anchorBody, movingBody, anchorBody.getWorldCenter());
revoluteJointDef.enableLimit = true;
revoluteJointDef.upperAngle = MathUtils.degToRad(40);
revoluteJointDef.lowerAngle = MathUtils.degToRad(-40);
physicsWorld.createJoint(revoluteJointDef);
And it works, I can move lever stick in left/right direction, and as it should you can not exceed proper angle, so this part is done. But now I’m looking for a way, when execute actions after moving this lever (for example open some doors/gate)
Here’s my basic idea, how to check which part of the stick has been touched by player (left or right) by creating stick’s body with this way:

So explaining, by adding 2 sensors, one on left side and one on right side, so in contact listener I would check which side has been touched.
But still I have no idea how to check if action should be performed, I know I could check on every update if stick angle is 40 or -40, but is it effective way? Or maybe there is better? I will be greatly thankful for any tips! Thanks
You don’t need to worry about efficiency here, the performance penalty for checking the angle is absolutely negligible. I measured the times needed to get the angle of a Sprite and a Body using the following code snippet:
So, on Desire Z it takes only 157 ns to find the angle of a Sprite and 393 ns to do the same with Body. It is also much simpler than using contact listeners. Just a side note, the angles of Sprites can be outside of (-360, +360) degrees if you rotate the Sprite.