A bit late but:
Another question that came when I was playing with projectiles and missile collision class : Which is the most efficient way, in a plugin, to know if the projectile/missile will score a hit on anything (ship, projectile, asteroid) at a given range ?
I was playing a bit with :
Vector2f projection = new Vector2f(collideDistance, 0f);
Vector2f location = proj.getLocation();
//List<ShipAPI> checkList = engine.getShips();
//List<ShipAPI> finalList = new LinkedList<>();
Vector2f point = CollisionUtils.getCollisionPoint(location, projection, proj);
if (point != null && MathUtils.getDistance(location, point) <= collideDistance) {
//Do something, change a variable, etc... In this case, change the collisionRadius and the collisionClass back to something that may hit the entity
}
But that doesn't seems to work, and I guess it's because my projectile is actually a missile with collisionRadius = 0 and collisionClass = NONE. Does that make "getCollisionPoint" null ?
Is there any other way to detect if a projectile without collision will intercept another entity ?
getCollisionPoint doesn't check collision class, only the vectors. Collision radius of zero might break it though. (Right-click on the method in your IDE and go to the method source to see details)
Your third arg for the method call needs to be whichever entity the projectile might hit, not the projectile itself.
Also the variable assigned to
projection means it'll only work for projectiles flying horizontally. To get the proper projection, multiply the projectile's velocity by the how far to extrapolate in seconds.
Although depending on what you're doing, you probably shouldn't even be using
getCollisionPoint, just
CombatUtils.getShipsWithinRange and the equivalent methods for missiles/asteroids followed by
CollisionUtils.isPointWithinBounds.