Game Development Reference
In-Depth Information
Vector2f waypoint2D = new
Vector2f(waypointPosition.x, waypointPosition.z);
float distance = aiPosition.distance(waypoint2D);
8. If the distance is more than 1f , we tell the spatial to move in the direction of the
waypoint. This recipe uses the GameCharacterControl class from Chapter
2 , Cameras and Game Controls :
if(distance > 1f){
Vector2f direction =
waypoint2D.subtract(aiPosition);
direction.mult(tpf);
spatial.getControl(GameCharacterControl.class).setViewDirection(new
Vector3f(direction.x, 0, direction.y).normalize());
spatial.getControl(GameCharacterControl.class).onAction("MoveForward",
true, 1);
}
9. If the distance is less than 1f , we set waypointPosition to null .
10. If waypointPosition is null, and there is another waypoint to get from the
pathfinder, we tell the pathfinder to step to the next waypoint and apply its value
to our waypointPosition field as shown in the following code snippet:
else if (!pathfinderThread.isPathfinding() &&
pathfinderThread.pathfinder.getNextWaypoint() != null
&& !pathfinderThread.pathfinder.isAtGoalWaypoint() ){
pathfinderThread.pathfinder.goToNextWaypoint();
waypointPosition = new
Vector3f(pathfinderThread.pathfinder.getWaypointPosition());
}
Search WWH ::




Custom Search