Be a Supporter!

how to make smart enemys

  • 316 Views
  • 7 Replies
New Topic
nanocon
nanocon
  • Member since: May. 29, 2007
  • Offline.
Forum Stats
Member
Level 04
Blank Slate
how to make smart enemys 2012-03-25 13:09:16

you see i kinda only know how to make ennemys that towards u and attacks (because of tutorials i read on ng.but i need them to dodge fight (in a somwat smart way) work to gather and all around be a joy to fight um also i am not a programer so i need like the actual script/code or a tutorial but not like a bunch of ai therys that explain nothing about how to actually do it or perhaps a programer or sonthing else along those lines

Plebbi
Plebbi
  • Member since: Jul. 1, 2003
  • Offline.
Forum Stats
Member
Level 13
Blank Slate
Response to how to make smart enemys 2012-03-25 13:16:26

At 3/25/12 01:09 PM, nanocon wrote: you see i kinda only know how to make ennemys that towards u and attacks (because of tutorials i read on ng.but i need them to dodge fight (in a somwat smart way) work to gather and all around be a joy to fight um also i am not a programer so i need like the actual script/code or a tutorial but not like a bunch of ai therys that explain nothing about how to actually do it or perhaps a programer or sonthing else along those lines

So basically you need someone to write it for you and you just use it, common man.. Your best bet is to read upon this stuff, if you know how to make them go towards you because of attacks, reverse it, make your bullet or whatever you use when it is about to hit them they have a timer to get away that way you have to shoot and maybe jump and shoot to hit them, or just read upon AI articles regarding AS2-AS3.. And i know you said you weren't a programmer but it's never to late to learn few things, im reading right now upon AS3 because AS that i know is currently out of date and id like to stay current with things :).. do that to, people will help you with your code here if you ask maybe a question and have a code for them to look at, but you will not get people to do the shitwork for you so you can post it in your game.. At least not for free that is..

You can always hire a programmer :)..

Plebbi
Plebbi
  • Member since: Jul. 1, 2003
  • Offline.
Forum Stats
Member
Level 13
Blank Slate
Response to how to make smart enemys 2012-03-25 14:01:48

At 3/25/12 01:16 PM, Plebbi wrote:
At 3/25/12 01:09 PM, nanocon wrote: you see i kinda only know how to make ennemys that towards u and attacks (because of tutorials i read on ng.but i need them to dodge fight (in a somwat smart way) work to gather and all around be a joy to fight um also i am not a programer so i need like the actual script/code or a tutorial but not like a bunch of ai therys that explain nothing about how to actually do it or perhaps a programer or sonthing else along those lines
So basically you need someone to write it for you and you just use it, common man.. Your best bet is to read upon this stuff, if you know how to make them go towards you because of attacks, reverse it, make your bullet or whatever you use when it is about to hit them they have a timer to get away that way you have to shoot and maybe jump and shoot to hit them, or just read upon AI articles regarding AS2-AS3.. And i know you said you weren't a programmer but it's never to late to learn few things, im reading right now upon AS3 because AS that i know is currently out of date and id like to stay current with things :).. do that to, people will help you with your code here if you ask maybe a question and have a code for them to look at, but you will not get people to do the shitwork for you so you can post it in your game.. At least not for free that is..

You can always hire a programmer :)..

I can point out one more thing for you, you could find a game you like, get the swf file of it and decompile it using a decompiler BUT ONLY FOR LEARNING PURPOSES! not to post it again as your own hehe, but to read the script and try make some sense of it, but the best bet always is to read a tutorial guidelines where each line is explained properly and you understand "ahh so if i do this, then this happens now i get it now i understand why the if and else and while are there..."

alwayssim
alwayssim
  • Member since: Dec. 4, 2011
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to how to make smart enemys 2012-03-25 14:10:06

At 3/25/12 01:09 PM, nanocon wrote: you see i kinda only know how to make ennemys that towards u and attacks (because of tutorials i read on ng.but i need them to dodge fight (in a somwat smart way) work to gather and all around be a joy to fight um also i am not a programer so i need like the actual script/code or a tutorial but not like a bunch of ai therys that explain nothing about how to actually do it or perhaps a programer or sonthing else along those lines

I think you're asking for too much in one go.

I think the best way to solve any problem is to break it down into smaller and smaller problems. If you break it down and still can't solve it, break it down even further.

For example, lets say you want your enemy to try and dodge a bullet that you've shot at it.

Lets break it down into smaller problems:

1) We need the enemy to detect when you've fired a bullet
2) We need the enemy to detect whether he is in the projcted path of the bullet
3) If so, we need the enemy to decide which way to move to dodge it
4) We need to make the enemy move in the required direction

Lets break it down further:

1)
1.1) Every time you 'fire a bullet' make it so that the position and velocity is recorded. You can do this by creating 4 arrays. Two for the x and y position and 2 for the speed in the x and y direction.
1.2) When a bullet has been removed for whatever reason, the data will have to be taken out of the arrays.
1.3) The enemy can then detect how many bullets are in play by looking at the length of the arrays. They can then also pin point the location and velocity of the four bullets by looking at the elements of the arrays.

2)
2.1) Run through each bullet with a for loop and work out the projected path of the bullet.
2.2) If the enemy intercepts this path then you know it is in the way of a bullet.

3)
3.1) First we need to decide how we want the enemy to move. A basic method would be to make the enemy move perpendicular to the direction of the bullet, either left or right. A more advanced method may take into account other objects and have more options as to where it can go to dodge.
3.2) Once we have decided the different directions the enemy could move in, analyse each option. For each option, run through a list of possible problems/benefits that could be incurred. For example:
-Would the move cause the enemy to be in the line of another bullet? If so, how far away is the bullet (i.e. how much of a risk is it currently).
-Would the move cause the enemy to be close to objects that it doesn't want to get close to.
3.3) After analysing each option, you need to come up with a method to decide which option is best. Maybe the best option isn't to move at all.

4)
4.1) After deciding which way to make the enemy move, we need to actually move the enemy. First translate the required direction to an x and y element. Then adjust the enemies x and y positions by the appropriate amount.

And you're done. This post was more to try and illustrate the amount of thought that needs to go into programming rather than a tutorial on how to do it. Each one of the problems above can be broken down into many smaller ones. If you need help breaking down the problems further, let me know which ones and I'll see if I can help.

Plebbi
Plebbi
  • Member since: Jul. 1, 2003
  • Offline.
Forum Stats
Member
Level 13
Blank Slate
Response to how to make smart enemys 2012-03-25 14:14:03

Jesus, if you ever create this enemy. It's gonna be the smartest AI ever haha, i wouldn't wanna play a game where the dude is like unbeatable haha just by reading that layout it sounds incredible AI..

alwayssim
alwayssim
  • Member since: Dec. 4, 2011
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to how to make smart enemys 2012-03-25 14:23:43

At 3/25/12 02:14 PM, Plebbi wrote: Jesus, if you ever create this enemy. It's gonna be the smartest AI ever haha, i wouldn't wanna play a game where the dude is like unbeatable haha just by reading that layout it sounds incredible AI..

Lol, it's not really advanced at all. All it does is a quick look around to see which direction looks most inviting and makes it move that way.

Also, well written AI doesn't mean harder AI. Another step that could be added is to make the enemy make mistakes at times. When you have analysed each option, you could make it so that every now and then it picks the second or third best option. You could even go as far to make it so that if the enemy has been shot at recently, it's not as good at making decisions as if it hasn't.

The point I was trying to get at is that whenever you make a decision you take many things into account.

Plebbi
Plebbi
  • Member since: Jul. 1, 2003
  • Offline.
Forum Stats
Member
Level 13
Blank Slate
Response to how to make smart enemys 2012-03-25 15:01:31

Yes, what i meant is that if your AI always chose the right path every time, he would be way to hard you would have to factor in things like tripping down or aiming incorrectly otherwise it would be like Counterstrike + Aimbot.

Anyway, you have a good idea of AI but i checked your profile and you have never done anything in flash, at least submitted in here, i did put few things that got removed in the website overhaul when a certain type of flash would be removed due to copyright infringements... But i have never battled with AI while making my games, but currently now i am back into flash after 6 years and reading upon AS3 to stay current. So it's just AS3 101 for me ;D to many things changed.. But i am going to program something later when i have read upon AS3. I have already an Idea in my head about a Sidescroller game, nothing "alien hominid" big hehe im no Dan Paladin or TomFulp ;D but im gonna program something that i can be happy with..

Anyway, off to dinner

ReNaeNae
ReNaeNae
  • Member since: Sep. 1, 2004
  • Offline.
Forum Stats
Supporter
Level 29
Blank Slate
Response to how to make smart enemys 2012-03-25 15:58:39

Same topic, same thread, please ;)