Can not move my object (noob)

I have setup a very primitive scene with a terrain(box) and 2 objects (another box and a sphere)

I am trying to set up some keybindings in order to move my object by it seems as though it ignores my key pressing.

the code follows:



import com.jme.app.SimpleGame;
import com.jme.scene.shape.Sphere;
import com.jme.scene.shape.Box;
import com.jme.math.Vector3f;
import com.jmex.physics.*;
import com.jme.light.PointLight;
import com.jme.scene.state.LightState;
import com.jme.renderer.ColorRGBA;
import com.jmex.physics.effects.Attractor;
import com.jme.bounding.BoundingBox;
import com.jme.bounding.BoundingSphere;
import com.jme.bounding.OrientedBoundingBox;
import com.jme.input.KeyBindingManager;
import com.jme.input.KeyInput;
public class Main extends SimpleGame{
    Box h;
    public static void main (String[] args)
    {
        Main app = new Main();
        app.setDialogBehaviour(SimpleGame.ALWAYS_SHOW_PROPS_DIALOG);
        app.start();
       
    }
     protected void simpleInitGame() {
     PhysicsWorld.create();
     Sphere b=new Sphere("My sphere",15,15,1f);
     b.setModelBound(new BoundingSphere());
     b.updateModelBound();
     b.setSolidColor(ColorRGBA.red);
     rootNode.attachChild(b);
     DynamicPhysicsObject s = new DynamicPhysicsObject(b,.5f);
     PhysicsWorld.getInstance().addObject(s);
     s.setGravityMode(1);
     s.setEnabled(true);
     s.syncWithGraphical();
     h = new Box("mymovingbox",new Vector3f(9, -8, 0), 1f,1f, 1f);
     h.setModelBound(new OrientedBoundingBox());
     h.updateModelBound();
     h.setSolidColor(ColorRGBA.red);
     rootNode.attachChild(h);
     DynamicPhysicsObject d = new DynamicPhysicsObject(h,15f);
     PhysicsWorld.getInstance().addObject(d);
     KeyBindingManager.getKeyBindingManager().set("for",KeyInput.KEY_1);
     KeyBindingManager.getKeyBindingManager().set("left",KeyInput.KEY_2);
     KeyBindingManager.getKeyBindingManager().set("back",KeyInput.KEY_3);
     KeyBindingManager.getKeyBindingManager().set("right",KeyInput.KEY_4);
     rootNode.updateWorldData(1f);
     d.setGravityMode(0);
     d.setEnabled(true);
     d.syncWithGraphical();
     Box c = new Box ("Terrain", new Vector3f (-10, -10, -10), 1000,1, 1000);
     StaticPhysicsObject myTerrain = new StaticPhysicsObject(c);
     c.hasCollision(c, true);
     c.setModelBound(new BoundingBox());
     c.updateModelBound();
     rootNode.attachChild(c);
     PhysicsWorld.getInstance().addObject(myTerrain);
     myTerrain.syncWithGraphical();
     LightState ls=display.getRenderer().createLightState();
     PointLight pl = new PointLight();
     pl.setEnabled(true);
     pl.setAmbient(ColorRGBA.green);
     ls.attach(pl);
     rootNode.setRenderState(ls);
     rootNode.updateWorldBound();
   }
     protected void simpleUpdate() {
     Vector3f v = new Vector3f(h.getLocalTranslation());
     if (KeyBindingManager.getKeyBindingManager().isValidCommand("for", false)) {
     v.x = v.x+.1f;
     h.setLocalTranslation(v);
     }
     if (KeyBindingManager.getKeyBindingManager().isValidCommand("left", false)) {
      v.y = v.y-.1f;
     h.setLocalTranslation(v);
     }
     if (KeyBindingManager.getKeyBindingManager().isValidCommand("back", false)) {
     v.x = v.x-.1f;
     h.setLocalTranslation(v);
        }
     if (KeyBindingManager.getKeyBindingManager().isValidCommand("for", false)) {
     v.y = v.y+.1f;
     h.setLocalTranslation(v);
        }
        PhysicsWorld.getInstance().update(1f);
    }
}



I know that I am missing something here but I cannot figure out exactly what :P

Thank you very much

PS: Irrelevant but I just figure out and would like to be of help to other noobs as me.
I used to get an OPENGLException 1281 with a 3ds model and it was fixed when I changed the textures from tga format to bmp.
I also got texture loading problems when loading 3ds files and having jpg textures so I ust converted them to jpg

Don't know about your specific example (don't have physics installed here at the moment), but below is something that should work.

Of course it only moves a bit (with 1 keypress). Change false to true if you want the event to repeat, like this:



if (KeyBindingManager.getKeyBindingManager().isValidCommand("for", true)) {



import com.jme.app.SimpleGame;
import com.jme.input.KeyBindingManager;
import com.jme.input.KeyInput;
import com.jme.math.Vector3f;
import com.jme.scene.shape.Box;

public class TestMove extends SimpleGame {

   public static void main(String[] a) {
      TestMove app = new TestMove();
      app.setDialogBehaviour(SimpleGame.ALWAYS_SHOW_PROPS_DIALOG);
      app.start();
   }

   Box h;
   protected void simpleInitGame() {
      h = new Box("mymovingbox", new Vector3f(9, -8, 0), 1f, 1f, 1f);
      rootNode.attachChild(h);
      KeyBindingManager.getKeyBindingManager().set("for", KeyInput.KEY_F);
   }

   protected void simpleUpdate() {
      if (KeyBindingManager.getKeyBindingManager().isValidCommand("for", false)) {
         System.out.println("F pressed");
         h.getLocalTranslation().x += 0.1f;
      }
   }

}

Thanks llama, it was more or less what I was doing.

it was a physics staff I had to resync the movement with the DynamicPhysicsObject that was bound with h.

I just fixed it by

d.synchwithGraphical();



Thanks again for your immediate reply

I would like to note here that moving physics objects simply by changing their location is not a very good idea. Consider moving them with forces or even desired velocities (joints) to get better physical effects.