Would this be the correct way to make AI? (Idea, no code)

I'm using java and I'm currently making a Open World space games with massive battles and such. Right now my focus is the AI and on how they would move around their targets. My idea right now is to use a waypoint system. So basically the entity would generate a random waypoint within a certain range from their target, rotate towards it , move towards it, and repeat the process once it has reached it. Since the ships in the game have auto rotating weapons and such, I thought this system would add a lot of dynamic-ness. Would this be a good idea for the navigation of the entities, or not? If not, could you please point me in the right direction?

I am working on something that is pretty similar to explain and I’m just doing it by having a global task list and letting every AI chose its next target by easiness to reach every frame and then just rotate/move/shoot towards it. Possibly not the best way, but works fine so far.

Well for each target I’d have a level of importance. Eg, small drone is 20 away with an importance of 5 or something while big scary mothership is 50 away with an importance of 20. I would write some code that would choose to go to a certain ship if it’s more important (range based on level of importance) rather than a less important ship that’s closer. Not sure what the algorithm would be, but it shouldn’t be too difficult.

@Slyth2727

You could:

double targetStrength = entity.getDistance(this) * entity.getImportance(); 
// requires an entity class with a getDistance(Entity) method

and then give each entity a certain [icode]targetRange[/icode] and target the entity closest to the target range.

CopyableCougar4

 I never thought of having this run by level of importance, thank you. This is perfect for what I felt was missing. Also, thank you for the code snippet it helped clear it up a little.

You could also take into account whether or not the enemies are firing at you. (Or have you targeted)

Yeah, something like this:

double targetStrength = entity.getDistance(this) * entity.getImportance(); 
if (entity.isTargeting(this)) targetStrength *= targetFactor;
else targetStrength /= targetFactor;

CopyableCougar4

I am also making a similar game and another thing to take into account is how many units from the same team are attacking a given target. You don’t want half of a fleet all going after 2 or 3 small ships just because they are closer. You could maintain a global list of who is targeting who, and query it as part of your algorithm.

You don’t want to make the AIs too smart either. Most soldiers don’t aim their guns in a firefight…

@ags1: The fact that they are rethinking every frame and possibly change their plan before even being able to complete it kinda solves that in my case.

How does this make sense? The further the target is the bigger the strength? Better:


Math.max(0, entity.getImportance() - entity.getDistance(this) / distanceFactor);

Say [icode]distanceFactor[/icode] is 10 for Slyth2727’s example, the small drone now has an importance of 3 and the big mother ship 15. Another small drone the same distance as the mother ship would now be 0.

A better way to do it would be for the strength to be an inverse logarithmic curve rather than linear.

@ra4king

I think I should have put:

double targetStrength = (1 / entity.getDistance(this)) * entity.getImportance(); 
// requires an entity class with a getDistance(Entity) method

I am aware that this is not an ideal situation, but I think it should work well. Granted, with the distance raised to the -1 power. I should have put that (1 / …) in the original.

CopyableCougar4