Created
October 1, 2012 10:56
-
-
Save BobTheBuilderBot/3810939 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(); | |
| 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