How to make AI

So I’m making a fighting game and I need some ai. Can someone help?

AI is pretty difficult to achieve

for many cases random() can fool you and looks like a well programmed AI :grin:

for your enemy you may want to preset a group of actions based on player relative position and state.
It’s likely you want to pick randomly one of these presets
… and you may want to dull the reflexes of your AI to make it less invincible

1 Like

Well, it really depends on what type of fighting game it is that you need the ai for. Is it a platformer, or a normal 2d game?

Also, something almost everyone uses for ai’s is this:

var player= PlayerName //plug in the player name!
var speed=12;
if(this.x>player.x){
this.x-=speed;
}
if(this.x<player.x){
this.x+=speed;
}
if(this.y>player.y){
this.y-=speed;
}
if(this.y<player.y){
this.y+=speed;
}

This only makes the object follow the player. If you don’t want it to move diagonal directions, just add “else” after every statement, and some fancy “}” for an ending

1 Like

Agree. This is like asking for a complete project. It is not something minor to help you with.

healthDemo.wick (4.4 KB)
This is a demo, just like @blurredPixels said, you can use random(). Here you go!

hello there