Skip to content

Instantly share code, notes, and snippets.

@BobTheBuilderBot
Created October 1, 2012 10:56
Show Gist options
  • Select an option

  • Save BobTheBuilderBot/3810939 to your computer and use it in GitHub Desktop.

Select an option

Save BobTheBuilderBot/3810939 to your computer and use it in GitHub Desktop.
public void update(float tpf) {
for(Queue<MoveAction> actionQueue : movementActions.values()) {
if(actionQueue.isEmpty()) continue;
MoveAction action = actionQueue.peek();
Character entity = action.getSource();
if(action.getStartPosition().equals(Vector3f.ZERO)) {
action.setStartPosition(new Vector3f(entity.getPosition()).setY(0));
}
Vector3f destination = action.getStartPosition().add(action.getTargetPosition()).setY(0);
Vector3f direction = getDirection(action.getTargetPosition()).mult(entity.getVelocity());
Vector3f currentPosition = entity.getPosition().clone().setY(0);
Vector3f nextPosition = currentPosition.add(direction).setY(0);
float distance = currentPosition.distance(destination);
float nextDistance = nextPosition.distance(destination);
entity.getControl().setWalkDirection(direction);
// When position is reached...
if(nextDistance > distance) {
entity.getControl().setWalkDirection(Vector3f.ZERO);
actionQueue.remove();
actionHandler.actionFinished(action);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment