How do I make AI

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By andrewtu0182

Make AI can move its self and predict the player’s way

Is this 2d or 3d. what kind of enemies is this, (spaceships, people, monsters) what perspective is the game?

Millard | 2020-06-16 16:23

:bust_in_silhouette: Reply From: Xascoria

What you asked here is incredibly broad and will have big difference depending on what type of games you are making, but here’s some general steps.

First you need write the implementations that allow the an Agent to interact with your game, like a character that can walk, shoot, stop etc.

Then you’ll need to write an algorithm that decide what this Agent can “detect”, can it see the environment around itself, can it sense how far away is the player?

Then is the main logical part. From the inputs given to the agent, the agent will make a decision on what to do then execute it, this part depends on how you want the agent to act so you’ll have to figure out what you want.

:bust_in_silhouette: Reply From: njamster

Making AI move is not hard, just change it’s position:

func _process(delta):
    position.x += 1

Now of course that’s not what you really want. But there is no way for me (or anyone else) to know what exactly you’re after, unless you state it here very clearly.¹

Predicting where the player will move is in a completely different ballpark: not only is it outright impossible without knowing how your player is moving at all, but it requires your AI to plan ahead as the player will continue to move while your AI is trying to cut its way. Also in most games you likely don’t want the AI to be perfect at this or playing your game will become extremely frustrating. Coding a prediction mechanism that’s good enough to feel challenging, but bad enough to be beatable is hard!
There is a reason why people have written entire (and very thick!) books about AI. And there is a reason why we’re still not living in a world, where machines have overtaken decision making. If you’re just starting out making games, try to keep things as easy as possible! Which usually means: stay away from too complex enemy behavior.

I don’t agree with downvoting your question (like other people did) as it isn’t a bad question really. It’s just way to broad to provide you with a meaningful answer and signals heavily that you’re lacking the experience necessary to pull this off. Work out the basics first and you will be able to come up with a much more detailed question. Just because you want something doesn’t mean you should start with it!

¹ A few examples: Are you working in 2D or 3D? What kind of game do you envision? Can your enemies jump? How fast are they? Can they communicate? How many are there? Which nodes do you use to implement them? Are there any obstacles? Is the range after which an AI will spot and track the player limited? Is the movement grid-bound or free? Do you use any algorithms for path-finding like A*?

I upvoted this question just because I don’t agree with downvoting. :slight_smile: Plus I find AI interesting and like questions about them. The question is a bit to broad, but It could be edited to be more specific. :slight_smile:

Millard | 2020-06-16 16:20