I'm building a game with Unity3D. It's a Gravity Wars clone. Both player and AI turrets shoot missiles at each other (giving an Angle and a Power variables), trying not to crash missiles on planets. But here's my question: how do I make AI calculate power and angle before shooting his missile, considering a planet's gravity too?
|
You should be able to simulate a shot, without drawing it. Then you could say, simulate 10 shots, and then take the closest one of the 10. |
|||
|
|
|
Given that the trajectory of the missle is based on the inputs of The basic (psuedo) AI steps are as follows:
You could of course just have the AI fire at random levels for both inputs, which could produce some interesting results... |
|||||||||||
|
|
How about making it realistic by not having them calculate, but starting with a guess and adjusting appropriately? When I played Gravity Wars, this is what I did; start with a semi-random power, and adjust accordingly by an increment. Within a couple of shots, you get really close. |
|||
|
|
|
A system like this, with multiple bodies, is going to be chaotic. I don't think that you would be able to solve an equation for it in real-time. The best you can hope is to find a solution using a genetic algorithm; 1: produce a number (e.g.100) of random solutions (angle, power pairs). 2: simulate these solutions. 3: if any of these, end up hitting the target (or coming sufficiently close), Done! otherwise continue. 4: pick best 10 solutions (ones that end up closest to the target) 5: from these 10 solution, create 10 children for each, by randomly adjusting their angle and power. 6: now you have 100 new solutions, got back to step 2 You will need to limit the number of iterations, in case there is no solution to be found, or it is taking too long to search. Even this approach is not guaranteed to find good solution because; 1. solution might not exist 2. in a chaotic system, small changes to a solution can have a huge impact on the result |
|||
|
|
