I am trying JME and managed to load model and move model to the direction of camera in first person controller. I have poor vector math, but need to (chase the player) rotate or move enemy model as camera (player) moves through the world.
I am using following class for model moving to which I am passing cam.getDirection() vector. I am want enemy to follow the player as an when player moves in any direction.
class ModelAnimator extends Controller {
Node model;
float velocity = 0.001f;
float max = 1.20f;
float turnSpeed = 0.001f;
Vector3f direction;
ModelAnimator(Node model, Float distance, Vector3f direction) {
this.model = model;
//reverse the direction to follow camera
this.direction = direction.negate();
this.direction.normalizeLocal();
}
public void update(float time) {
/******************************************************
* Determine the location of the camera and then move the enemy.
*/
Vector3f modelPos = model.getLocalTranslation();
modelPos.addLocal(direction.mult(velocity));
model.setLocalTranslation(modelPos);
}
}