Game Development Reference
In-Depth Information
character.onAction(name, isPressed, tpf);
}
3. Now, create a new method called fire . This is where we're going to add most of
the new functionalities. Inside this, we first define a new Ray class that we place
at the camera's location (if it is an FPS), and we set the direction to be the same as
the camera's direction, as shown in the following code:
Ray r = new Ray(app.getCamera().getLocation(),
app.getCamera().getDirection());
4. Then, create a new CollisionResults instance, which we will use to keep
track of collisions. We parse through the target list to see whether Ray collides
with any of them. All collisions are stored in the CollisionResults instance
as follows:
CollisionResults collRes = new CollisionResults();
for(Geometry g: targets) {
g.collideWith(r, collRes);
}
5. Afterwards, check whether there have been any collisions. If so, get the nearest
one and display the location as follows:
if(collRes.size() > 0){
System.out.println("hit " +
collRes.getClosestCollision().getContactPoint());
}
6. Finally, call the character's onFire method, character.onFire(); .
Search WWH ::




Custom Search