PDA

View Full Version : Determining hit angles, etcetera

Robert Kosek
17-08-2007, 08:34 PM
I'm looking to do a little something and write a small game, but I'm looking to do something I really don't know much about. The basic idea is that you design your own spaceship based on a base hull template with various sections, slots per section, and hitpoints. The sections would be things like "front", "port", "starboard", "rear" and would all mount various devices.

But there's a few problems I'm not sure on how to solve. Mostly I have the ideas and the basic steps/math behind each, but I'm not sure which is best. I want to let things get destroyed in a section if it gets hit; I want to permit firing arcs based upon where a weapon or defense is mounted; also I want to permit the piercing of a side to finish a ship.

I have a few "methods" at my disposal, but none really make me happy.

1) Calculate the incoming path as a line and test collision against a circle around the ship spliced into X (undecided, maybe 36) sections to determine the incoming angle. I could then resolve this angle down to a given section and run the simulations as needed.

2) Somehow turn the arc into a sector, "slice of pie" for those who don't understand what the sector of a circle is, using the angular width, range, and anything else I need. However, while I might be able to figure out the sector parts I cannot figure out how to tell if a point is in a given sector. This is the easiest way I can figure to use without any workarounds, but without the knowledge of finding a point in a sector I have no clue.

3) Fudge the sector calculations by constructing a polygonal shape and then using a "point in polygon" method for each angle. Still kinda messy because I'd have to test per polygon and section.

4) Perhaps, if it'd work, use ArcCos to find the incoming angle. Though it still wouldn't tell me if it were in a sector ... just at which angle to the ship the point is upon collision.

I like method 2 the best because for calculating firing arcs it is the easiest. If you're simulating a tail-gunner with a 120¬? swing on his lasers it seems simpler to try a point-in-sector to fire. I could still do it by determining the angle to the point with ArcCos and resolve downwards through the sectors and weapons, but that might be a little slower.

I'm still trying to figure out how I'd go about compiling things down in generating a usable template from the given designs, but the collision with incoming fire and simulated firing arcs on a ship is troublesome to me. Does anyone have any input, advice, or suggestions?

Ooh, I just thought of this but how would I go about coding a lesser AI to figure out what firing arc is best and which way to turn to hit a target? That bothers me a little more I think... :?

Thanks in advance for any help. I'm in no real hurry so don't think that you don't have time to respond. I just can't find anything out there so I kind of have to ask here.

Edit:

Just thought about it some more, but I think I've got the best I can come up with on my own. I'll be using rectangular collision boxes, and collisions with projectiles can use ArcCos for detecting the angle. But for a rectangular body this isn't so good as some things might be considered the rear when it is the side. So per ship this will have to be tweaked somewhat. I can't just test the sides of the rectangle to check because the ship may have two sections on the port and starboard sides on a battleship.

For firing arc detection I can do a range check first, followed by a test to see if the local angle is within the firing arc. Only then will it be "true". It'll work I think, but I've probably represented it in an oversimplified manner.

But I still can't quite figure out how to make a ship AI that says "turn this way to fire a broadside!" while the anti-fighter guns are already firing at the nearest targets in their arcs. :?

JernejL
17-08-2007, 09:33 PM
Calculate impact angles relative to the object, and divide it into sections, i do that, it works well, it works fast - it is efficient.