Move node at mouse click

I added my model physics.

    startPosition = new Vector3f(-70.0f, 5.1f, 70.0f);
    tank.setLocalTranslation(startPosition);
    tank.updateModelBound();
    scene.attachChild(tank); 
   
    RigidBodyControl map_phy;
    map_phy = new RigidBodyControl(0.0f);
    nodeMap.addControl(map_phy);
    bulletAppState.getPhysicsSpace().add(map_phy);
    RigidBodyControl tank_phy;
    tank_phy = new RigidBodyControl(2f);
    tank.addControl(tank_phy);
    bulletAppState.getPhysicsSpace().add(tank_phy);

And the code move:

  @Override
   public void simpleUpdate(float tpf) {
    float i = 0.0003f;
      if(click){
          Vector3f newPoint = FastMath.interpolateLinear(i, startPosition, newPosition);
          tank.setLocalTranslation(newPoint);
          tank.lookAt(startPosition, Vector3f.UNIT_Y);
         startPosition = newPoint;
      }
 }

Model not moving. But without physics model moves. Where did I go wrong?

The physics control sets the location of the object. As soon as you use physics you have to do the movement via the physics object.

1 Like