Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save BobTheBuilderBot/3810932 to your computer and use it in GitHub Desktop.
@Override
public void update(float tpf) {
Vector3f camDirection = new Vector3f(camera.getDirection());
Vector3f camLeft = new Vector3f(camera.getLeft());
camDirection.setY(0); camLeft.setY(0);
targetPosition.zero();
// Fire move action to send to server.
if(lastUpdatePosition.distance(playerCharacter.getPosition()) >= MOVEMENT_UPDATE_FREQUENCY) {
MoveAction moveAction = new MoveAction(playerNode.getWorldTranslation().subtract(lastUpdatePosition));
moveAction.setAnimated(false);
playerCharacter.action(moveAction);
lastUpdatePosition = new Vector3f(playerNode.getWorldTranslation());
System.out.println(String.format("Move Action " + moveAction.getTargetPosition()));
}
for(Direction direction : inputDirection) {
switch(direction) {
case Left:
targetPosition.addLocal(camLeft);
break;
case Right:
targetPosition.addLocal(camLeft.negateLocal());
break;
case Forward:
targetPosition.addLocal(camDirection);
break;
case Backward:
targetPosition.addLocal(camDirection.negateLocal());
break;
}
}
inputDirection.clear();
if(!inputLocked) {
playerCharacter.getControl().setWalkDirection(targetPosition.mult(playerCharacter.getVelocity()));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment