Game Development Reference
In-Depth Information
spatial.getControl(BetterCharacterControl.class);
}
10. Finally, in the controlUpdate method, we check whether usePhysics is
true . If it is, rather than updating the spatial like we normally do in the method,
we should instead set walkDirection of physicsCharacter to the local
one and set viewDirection to the forward vector of its rotation as follows:
if(usePhysics){
physicsCharacter.setWalkDirection(walkDirection.multLocal(50));
physicsCharacter.setViewDirection(tempRotation.getRotationColumn(2));
}
11. In our server's main class, inside the addPlayer method, we should now add
BetterCharacterControl to the player's spatial before we add Server-
PlayerControl , as shown in the following code snippet:
Node playerNode = new Node("Player");
playerNode.addControl(new
BetterCharacterControl(0.5f, 1.5f, 1f));
playerNode.addControl(player);
rootNode.attachChild(playerNode);
stateManager.getState(ServerPhysicsAppState.class).addPlayer(player.getPhysicsCharacter());
12. There also needs to be some logic to add and remove BetterCharacterCon-
trol from physicsSpace as it joins and leaves the game.
Search WWH ::




Custom Search