Created
September 29, 2012 12:27
-
-
Save BobTheBuilderBot/3803849 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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