record the tile grid position of the closest collision found
This commit is contained in:
parent
b791a041a2
commit
1d20d0700e
|
@ -19,8 +19,10 @@ public class TileMapSweptSphereCollisionChecker implements SweptSphereWorldColli
|
|||
|
||||
public TileMap tileMap;
|
||||
|
||||
public final TileCoord lastCollisionTilePosition = new TileCoord();
|
||||
|
||||
@Override
|
||||
public void checkForCollisions(SweptSphere sphere, BoundingBox possibleCollisionArea) {
|
||||
public boolean checkForCollisions(SweptSphere sphere, BoundingBox possibleCollisionArea) {
|
||||
if (tileMap == null)
|
||||
throw new UnsupportedOperationException("No TileMap object is set.");
|
||||
|
||||
|
@ -28,6 +30,8 @@ public class TileMapSweptSphereCollisionChecker implements SweptSphereWorldColli
|
|||
max.set(0, 0, 0);
|
||||
|
||||
float lastCollisionDistance = Float.MAX_VALUE;
|
||||
boolean foundCollision = false;
|
||||
lastCollisionTilePosition.set(0, 0, 0);
|
||||
|
||||
// TODO: I don't think we even need to check if the area overlaps ... ?
|
||||
// (it probably always will, right?)
|
||||
|
@ -77,8 +81,13 @@ public class TileMapSweptSphereCollisionChecker implements SweptSphereWorldColli
|
|||
// will contain info for the closest intersection
|
||||
// found
|
||||
boolean collided = SweptSphereCollisionTester.test(sphere, a, b, c);
|
||||
if (collided && sphere.nearestCollisionDistance < lastCollisionDistance)
|
||||
if (collided && sphere.nearestCollisionDistance < lastCollisionDistance) {
|
||||
foundCollision = true;
|
||||
lastCollisionDistance = sphere.nearestCollisionDistance;
|
||||
|
||||
// this is the closest collision found so far
|
||||
// record the grid position ...
|
||||
lastCollisionTilePosition.set(x, y, z);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -86,4 +95,7 @@ public class TileMapSweptSphereCollisionChecker implements SweptSphereWorldColli
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
return foundCollision;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue