Game Development Reference
In-Depth Information
There's moreā€¦
Currently, it's very difficult to visualize the results. Exactly what does the AI see? One way
of finding out is to create Lines for each ray we cast. These should be removed before
each new cast. By following this example, we will be able to see the extent of the vision.
The following steps will give us a way of seeing the extent of an AI's vision:
1. First of all, we need to define an array for the lines; it should have the same capa-
city as the number of rays we're going to cast. Inside the for loop, add the follow-
ing code at the start and end:
for(float x = -angle; x < angle; x+=
FastMath.QUARTER_PI * 0.1f){
if(debug && sightLines[i] != null){
((Node)getSpatial().getParent()).detachChild(sightLines[i]);
}
...Our sight code here...
if(debug){
Geometry line = makeDebugLine(ray);
sightLines[i++] = line;
((Node)getSpatial().getParent()).attachChild(line);
}
2. The makeDebugLine method that we mentioned previously will look like the
following code:
private Geometry makeDebugLine(Ray r){
Line l = new Line(r.getOrigin(),
r.getOrigin().add(r.getDirection().mult(sightRange)));
Geometry line = new Geometry("", l);
line.setMaterial(TestAiControl.lineMat);
return line;
}
This simply takes each ray and makes something that can be seen by human eyes.
Search WWH ::




Custom Search