jmonkey engine move object to object move object to position
package tests;
import com.jme3.app.SimpleApplication;
import com.jme3.light.AmbientLight;
import com.jme3.light.DirectionalLight;
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.Spatial;
import com.jme3.scene.shape.Box;
/**
* This is the Main Class of your Game. It should boot up your game and do initial initialisation
* Move your Logic into AppStates or Controls or other java classes
*/
public class Tests extends SimpleApplication {
public static void main(String[] args) {
Tests app = new Tests();
app.setShowSettings(false); //Settings dialog not supported on mac
app.start();
}
private float interp = 0.0f;
private float mySpeed = 2.0f;
Spatial player;
Spatial monster;
@Override
public void simpleInitApp() {
player = assetManager.loadModel("Models/cube.glb");
rootNode.attachChild(player);
monster = assetManager.loadModel("Models/cube.glb");
rootNode.attachChild(monster);
monster.move(5f, 0, 0);
setUpLight();
}
@Override
public void simpleUpdate(float tpf) {
Vector3f monsterPosition = monster.getLocalTranslation();
Vector3f playerPosition = player.getLocalTranslation();
float distance = playerPosition.distance(monsterPosition);
interp += (mySpeed/distance) * tpf;
if ( distance > 0.1f ) {
monster.setLocalTranslation(new Vector3f().interpolateLocal(monsterPosition, playerPosition, interp));
}
}
private void setUpLight() {
// We add light so we see the scene
AmbientLight al = new AmbientLight();
al.setColor(ColorRGBA.White.mult(1.3f));
rootNode.addLight(al);
DirectionalLight dl = new DirectionalLight();
dl.setColor(ColorRGBA.White);
dl.setDirection(new Vector3f(2.8f, -2.8f, -2.8f).normalizeLocal());
rootNode.addLight(dl);
}
@Override
public void simpleRender(RenderManager rm) {
//add render code here (if any)
}
}
Комментарии
Отправить комментарий