Game Development Reference
In-Depth Information
if (distance > 20f){
state = State.Idle;
target = null;
} else if(distance > 5f){
forward = true;
backward = false;
} else if (distance < 3f){
forward = false;
backward = true;
} else {
forward = false;
backward = false;
}
6. When it comes to movement, we can get the forward facing direction with the fol-
lowing line of code:
Vector3f modelForwardDir =
spatial.getWorldRotation().mult(Vector3f.UNIT_Z);
7. Depending on whether forward or backward is true, we can multiply this value
with a suitable movement speed, and the call setWalkDirection on the
BetterCharacterControl class with the result shown in the following
code:
if (forward) {
walkDirection.addLocal(modelForwardDir.mult(3));
} else if (backward) {
walkDirection.addLocal(modelForwardDir.negate().multLocal(3));
}
physicsCharacter.setWalkDirection(walkDirection);
8. Finally, we should also call setViewDirection , as shown in the following
code:
physicsCharacter.setViewDirection(viewDirection);
Search WWH ::




Custom Search