Sure !
Follow the entire code :
package mygame;
import com.jme3.app.SimpleApplication;
import com.jme3.font.BitmapFont;
import com.jme3.font.BitmapText;
import com.jme3.input.KeyInput;
import com.jme3.input.controls.AnalogListener;
import com.jme3.input.controls.KeyTrigger;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.renderer.RenderManager;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.shape.Box;
import com.jme3.scene.shape.Sphere;
public class Main extends SimpleApplication {
Node centernode = new Node();
Node nodestationary = new Node();
Node playerNode = new Node();
public static void main(String[] args) { new Main().start(); }
public Main() {super(null);}
@Override public void simpleInitApp() {
// Core Node
Sphere orbitsphere = new Sphere(32, 32, 0.1f);
Geometry orbitspheregeom = new Geometry("", orbitsphere);
Material orbitspheremat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
orbitspheremat.getAdditionalRenderState().setWireframe(true);
orbitspheremat.setColor("Color", ColorRGBA.Blue);
orbitspheregeom.setMaterial(orbitspheremat);
centernode.attachChild(orbitspheregeom);
rootNode.attachChild(centernode);
// Stationary box for initial rotation reference
nodestationary.setLocalTranslation(0, 0, 4.0f);
centernode.attachChild(nodestationary);
Box stationarybox = new Box(0.1f, 0.1f, 0.1f);
Geometry stationaryboxgeom = new Geometry("Box", stationarybox);
Material stationaryboxmat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
stationaryboxmat.getAdditionalRenderState().setWireframe(true);
stationaryboxmat.setColor("Color", ColorRGBA.Red);
stationaryboxgeom.setMaterial(stationaryboxmat);
nodestationary.attachChild(stationaryboxgeom);
centernode.attachChild(nodestationary);
// player Box
Box playerbox = new Box(0.1f, 0.1f, 0.1f);
Geometry playerboxgeom = new Geometry("Box", playerbox);
Material playerboxmat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
playerboxmat.getAdditionalRenderState().setWireframe(true);
playerboxmat.setColor("Color", ColorRGBA.White);
playerboxgeom.setMaterial(playerboxmat);
playerboxgeom.setLocalTranslation(0, 0, 4.0f);
playerNode.attachChild(playerboxgeom);
centernode.attachChild(playerNode);
inputManager.addMapping("left", new KeyTrigger(KeyInput.KEY_LEFT)); inputManager.addMapping("left", new KeyTrigger(KeyInput.KEY_A ));
inputManager.addMapping("right", new KeyTrigger(KeyInput.KEY_RIGHT)); inputManager.addMapping("right", new KeyTrigger(KeyInput.KEY_D));
inputManager.addMapping("up", new KeyTrigger(KeyInput.KEY_UP)); inputManager.addMapping("up", new KeyTrigger(KeyInput.KEY_W));
inputManager.addMapping("down", new KeyTrigger(KeyInput.KEY_DOWN)); inputManager.addMapping("down", new KeyTrigger(KeyInput.KEY_S));
inputManager.addMapping("space", new KeyTrigger(KeyInput.KEY_SPACE));
inputManager.addListener(analogListener, "left","right","up","down","space");
}
private AnalogListener analogListener = new AnalogListener() {
float speed=0.4f;
public void onAnalog(String name, float value, float tpf) {
if (name.equals("up")) { playerNode.rotate(-speed*5*tpf, 0, 0); }
if (name.equals("down")) { playerNode.rotate(speed*5*tpf, 0, 0); }
if (name.equals("left")) { playerNode.rotate(0,(speed*5)*tpf,0); }
if (name.equals("right")) { playerNode.rotate(0,(-speed*5)*tpf,0); }
if (name.equals("space")) {}
}
};
@Override public void simpleUpdate(float tpf) {
float distance = nodestationary.getWorldTranslation().distance( playerNode.getWorldTranslation());
System.out.println(distance);
}
}