Create a bounding <shape> for each ship, and test whether each bounding <shape> can see/is in range of the other's bounding <shape>, if they can't, then theres no way they can see each other at all, so there's no reason to check each sub-piece for visibility*.Lap wrote:Weapon Checks- Here's the tricky part
0. If it's time to find a new target...
1. Loop through all shapes throwing out shapes that are too far away.
* So long as the bounding <shapes> are properly sized, of cause.
I'm not real familiar with love.physics, but it looks like positions are associated with bodies, and bodies have positions. Personally I'd wager you are better off storing the data you need on the object itself in this instance, but I defer to those with more familiarity with the matter.---a. How do we determine the distance between two shapes? There is no shape:getPos() or equivalent that I know of.
While I can understand your interest in being accurate, it might be overkill in this instance; plenty of games have done fine with nothing but bounding-boxes.---b. If we get the center of a piece it's kind of inaccurate because the center might not be in range, but an edge might.
if you must, pixel-checking (of the part's imagedata) or clipping against its shape would probably work (remember to use Bounding shapes to determine if such a detailed check is required, though)
A page from the big book of FPS design might be helpful here.This last part could derail the whole project or at least drastically change all the guns to manual instead of auto-targetting, which makes this an entirely different game.
In an average FPS weapons are generally of one of two implementations: Projectile, and hitscan.
- Projectile weapons actually generate in-world objects, they actually move through the world, have whatever degree of physics is required, and trigger collision events when they hit something. This can get a bit hairy as the projectiles approach higher speeds, which is why hitscan exists.
- Hitscan weapons just make a line-check when they are fired. they either hit, or they don't. and you know right away.
Hitscan is obviously very simple; You do the check, apply the results. done.
Remember, these aren't free-floating objects, they are in neat little groups called shipsNow if I have to do that for every single physics.update that seems awful, especially considering box2d has to have the x,y of each shape stored somewhere.
As I suggested above, Bounding <shapes> greatly cut down the number of checks you need to do here.