Skip to content

Instantly share code, notes, and snippets.

@BobTheBuilderBot
Created September 29, 2012 12:27
Show Gist options
  • Select an option

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

Select an option

Save BobTheBuilderBot/3803849 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();
Entity entity = action.getSource();
if(action.getStartPosition() == Vector3f.ZERO) {
action.setStartPosition(entity.getPosition());
}
Vector3f destination = action.getStartPosition().add(action.getTargetPosition());
Vector3f direction = getDirection(action.getTargetPosition()).mult(entity.getVelocity());
Vector3f currentPosition = action.getSource().getPosition();
Vector3f nextPosition = currentPosition.add(direction);
// When position is reached...
float distance = currentPosition.distance(destination);
float nextDistance = nextPosition.distance(destination);
entity.getControl().setWalkDirection(direction);
if(nextDistance > distance) {
entity.getControl().setWalkDirection(Vector3f.ZERO);
actionQueue.remove();
actionHandler.onFinished(action);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment