Hey guys, so i have created an npc that randomly moves. I want to implement an aggro range so if you walk inside the range the npc walks towards you. So i made a cube and the cube is positioned perfectly when i first run the program and move if the npc moves, however the cube goes flying off the map and not relative to the npc.
My npc:
[java]
public class Ogre extends Node {
private BetterCharacterControl ogre;
private Box aggro;
private Geometry aggroRange;
}
public Ogre{
ogre = new BetterCharacterControl(1f, 10, 1f);
this.addControl(ogre);
}
[/java]
This is how the ogre moves:
[java]
movementTimer = new Timer();
movementTimer.schedule(new TimerTask() {
@Override
public void run() {
Random walk = new Random();
if (walk.nextInt(3) == 1) {
direction = walk.nextInt(8);
if (direction == 0) {
walkDirection.set(0, 0, walk.nextInt(5));
ogre.setWalkDirection(walkDirection.normalize().multLocal(movementSpeed));
}
if (direction == 1) {
walkDirection.set(0, 0, walk.nextInt(5) - 11);
ogre.setWalkDirection(walkDirection.normalize().multLocal(movementSpeed));
}
if (direction == 2) {
walkDirection.set(walk.nextInt(5) - 11, 0, walk.nextInt(5));
ogre.setWalkDirection(walkDirection.normalize().multLocal(movementSpeed));
}
if (direction == 3) {
walkDirection.set(walk.nextInt(5), 0, walk.nextInt(5) - 11);
ogre.setWalkDirection(walkDirection.normalize().multLocal(movementSpeed));
}
if (direction == 4) {
walkDirection.set(walk.nextInt(5), 0, 0);
ogre.setWalkDirection(walkDirection.normalize().multLocal(movementSpeed));
}
if (direction == 5) {
walkDirection.set(walk.nextInt(5) - 11, 0, 0);
ogre.setWalkDirection(walkDirection.normalize().multLocal(movementSpeed));
}
if (direction == 6) {
walkDirection.set(walk.nextInt(5), 0, walk.nextInt(5));
ogre.setWalkDirection(walkDirection.normalize().multLocal(movementSpeed));
}
if (direction == 7) {
walkDirection.set(walk.nextInt(5) - 11, 0, walk.nextInt(5) - 11);
ogre.setWalkDirection(walkDirection.normalize().multLocal(movementSpeed));
}
} else {
walkDirection.set(0, 0, 0);
ogre.setWalkDirection(walkDirection.normalize().multLocal(movementSpeed));
}
}
}, 0, 1000);
[/java]
I made the cube and in my update method:
[java]
ogre.aggroRange().move(ogre.getWalkDirection().normalize().multLocal(ogre.getMovementSpeed()));
[/java]
But like i said, the cube goes flying. It does stop when the ogre stops and moves when the ogre moves but where the ogre is.