Newbie to jmephysics: Limiting joint movement

Greetings all.

I've been looking around for a solution, but have been unsuccessful, so figured I'd bring it to the experts here.

I am trying to limit the movement of a hinge joint (i.e, how an arm stops at the elbow).

I'm guessing there is a setting I have to make for this happen, but not finding it.

I took a rookie stab at it by trying to get the location of the box, then syncing up the physics object with it,

but it goes crazy.

I then thought maybe the answer was to get the amount of force on it, and apply the same amount in the opposite direction to "stop" it,

but that is probably not right.

Any point in the right direction would be appreciated.  (I started looking at javadocs, but I'm still fighting my way through all this stuff and

wasn't able to find it for sure).

Thanks a lot in advance!!!

Here is my sample so far (p.s. also thanks to those folks I "borrowed" code from when looking at examples, in case you recognize some of yours :slight_smile: ).

Basically I'd like the box on top (box2) to go only from straight up to go right, and not go back to the left at all. 

import com.jme.input.KeyBindingManager;
import com.jme.input.KeyInput;
import com.jme.math.Vector3f;
import com.jme.scene.shape.Box;
import com.jme.scene.shape.Sphere;
import com.jme.scene.shape.Quad;
import com.jmex.physics.DynamicPhysicsObject;
import com.jmex.physics.PhysicsObject;
import com.jmex.physics.PhysicsWorld;
import com.jmex.physics.StaticPhysicsObject;
import com.jmex.physics.joints.HingeJoint;

public class brian4 extends SimpleGame {
   DynamicPhysicsObject box2p;
   Box box2;
   protected void simpleInitGame() {
      display.setTitle("Simple Test");

      KeyBindingManager kb = KeyBindingManager.getKeyBindingManager();
      kb.set("xforce", KeyInput.KEY_Z);
      kb.set("negativexforce", KeyInput.KEY_X);

        // Creates the box that makes out the floor (graphics only).
        Box floorGraphics = new Box("Floor", new Vector3f(0f,-0.5f,0f), 50, 0.5f, 50); //a 100x1x100 plane
        PhysicsObject floorPhysics = new StaticPhysicsObject(floorGraphics);

        //load a test box and join with another
        Box box1 = new Box("Box1", new Vector3f(0,1,0), 1f, 1f, 1f); // a 2x2x2 box
        DynamicPhysicsObject box1p = new DynamicPhysicsObject(box1, 10000f);

        box2 = new Box("Box2", new Vector3f(0f,8f,0f), 1f, 5f, 1f); // a 2x2x2 box
        box2p = new DynamicPhysicsObject(box2, 20f);

        HingeJoint hinge = new HingeJoint("Joint 1", box2p, box1p);
        hinge.setAnchor(new Vector3f(0.0f,3.0f,0.0f));
        hinge.setAxis(new Vector3f(0,0,1));

   protected void cleanup() {
      // Before ending your application you should always clean up the
      // PhysicsWorld.

   protected void simpleUpdate() {
      KeyBindingManager kb = KeyBindingManager.getKeyBindingManager();
      if (kb.isValidCommand("xforce", true)) {
         box2p.addForce(new Vector3f(10, 0, 0));
      } else if (kb.isValidCommand("negativexforce", true)) {
         box2p.addForce(new Vector3f(-10, 0, 0));
      Float test = (box2.getLocalTranslation().x);
      if (test>1)
         box2.setLocalTranslation(new Vector3f(0f, 8f, 0f));


   public static void main(String[] args) {
      brian4 app = new brian4();
      app.setDialogBehaviour(ALWAYS_SHOW_PROPS_DIALOG, brian1.class.getClassLoader()

Well folks,

I actually just found my mistake.

I changed:

box2.setLocalTranslation(new Vector3f(0f, 8f, 0f));



If a mod wants to delete this, please do.  I can't find how to delete my post if it's an option even.


Just saw the setMaxAngleStop and steMinAngleStop, that's probably a better way than trying to force it myself :slight_smile:

Glad you found your problem.  It usually better to leave these kinds of posts just in case someone else is having a similar problem can search the forums and see that you had the same problem and see the solution.