Game Development Reference
In-Depth Information
Vector3f leftDir =
spatial.getWorldRotation().getRotationColumn(0).mult(playerWidth);
6. We'll start by checking for low covers and set y to lowHeight as follows:
leftDir.setY(lowHeight);
7. Then, we create a for loop that sends three Rays: one at the left extreme of the
player, one in the center, and one to the right. This is done by multiplying
leftDir with i . The loop must then be duplicated for the upper Rays as well:
for(int i = -1; i < 2; i++){
leftDir.multLocal(i, 1, i);
ray.setOrigin(position.add(leftDir));
structures.collideWith(ray, collRes);
if(collRes.size() > 0){
lowCollisions++;
}
collRes.clear();
}
8. In order to be considered to be inside range of a cover, all three (left, middle, and
right) Rays must hit something. A high cover always has a low cover as well, so
we can check to see whether we've hit the low cover first. If we did, we do one
more Ray check to find out the normal of the actual triangle hit. This will help us
align the model with the cover:
if(lowCollisions == 3){
ray.setOrigin(spatial.getWorldTranslation().add(0,
0.5f, 0));
structures.collideWith(ray, collRes);
Triangle t = new Triangle();
collRes.getClosestCollision().getTriangle(t);
9. The opposite of the triangle's normal should be the character's new viewDir-
ection :
viewDirection.set(t.getNormal().negate());
Search WWH ::




Custom Search