This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2007-06-03 13:30:40

archmage
Scratcher
Registered: 2007-05-18
Posts: 1000+

Enemy AI Scripts

Since Ive decided to make enemies in draw your game 2 I AI scripts. They would be like the AIs you find in fighting games. I plan to make the something like this:

right of player:move left
left of player:move right
close to player: Begin attack script, pick random attack
sense item: go to item when touching pick it up

This of course is very rough and I also need to  make different difficulty settings  which will probably be created with wait X secs and randoms X to Y.

If you have any ideas for making this kind of AI or others please post.


Hi, I am Archmage coder extraordinaire. I do Scratch,pascal,java,php,html, AS2 and AS3. Leave me a message if you want coding advice. Also check out my personal website, lots of good stuff about web development, Flash, and Scratch (v1 and v2) !

Offline

 

#2 2007-06-07 15:02:37

technomage
Scratcher
Registered: 2007-05-17
Posts: 1

Re: Enemy AI Scripts

Capital has the best AI I have seen in a scratch game.
http://scratch.mit.edu/projects/jmgibson/7644
The ships and missles can follow you all over space and use real physics to calculate forces. I'm sure there is stuff you can learn from it.

Last edited by technomage (2007-06-07 15:02:59)

Offline

 

#3 2007-06-07 18:16:39

Mayhem
Scratcher
Registered: 2007-05-26
Posts: 1000+

Re: Enemy AI Scripts

Your badguy can use "point towards" to always know where the goodguy is, and then "move 10" will always move him forwards.

Use "distance to" to check how close you are.

Forever
Point towards Goodguy
wait 0.1
If (distance to goodguy)<50
- (use attack routine)
- Else
   Move 10


Web-spinning Spider:  http://scratch.mit.edu/projects/Mayhem/18456
3D Dungeon Adventure:  http://scratch.mit.edu/projects/Mayhem/23570
Starfighter X: http://scratch.mit.edu/projects/Mayhem/21825
Wandering Knight: http://scratch.mit.edu/projects/Mayhem/28484

Offline

 

#4 2007-06-08 00:55:52

jmgibson
Scratcher
Registered: 2007-06-03
Posts: 6

Re: Enemy AI Scripts

I'm going to have to thank technomage for the nod to Capital, but please, if you are going to look at my script for any education, don't look at the enemy ship.  It's attack looks smart and complex but its embarrassingly simple and uses the missile to hide what its really doing in the game.  Instead look at the physics I've built into the missile.  I consider that much more clever.

Offline

 

#5 2007-06-11 03:06:35

jmgibson
Scratcher
Registered: 2007-06-03
Posts: 6

Re: Enemy AI Scripts

P.S.  Maybe you mages can get together and have a mage party or something.   smile

Offline

 

#6 2007-06-21 07:53:05

bigB
Scratcher
Registered: 2007-06-09
Posts: 100+

Re: Enemy AI Scripts

i have AI opponents in two of my games.  1player ping pong and pacman.  both are fairly straightforward but affective. feel free to look.  pingpong may be more appropriate for you.


http://scratch.mit.edu/projects/bigB/260981 Draw to Text
http://scratch.mit.edu/projects/bigB/181829 3D Stunt Flyer

Offline

 

#7 2007-07-24 13:33:03

Slacker101
Scratcher
Registered: 2007-07-23
Posts: 60

Re: Enemy AI Scripts

I need something more simple then jmgibson. All I want is an enemy that will shot at you. What is the script for shooting in basic.

Offline

 

#8 2008-02-06 15:41:05

Lucario621
Community Moderator
Registered: 2007-10-03
Posts: 1000+

Re: Enemy AI Scripts

Well, Al's are not that hard to make. My Al's In my super awesome game named "Super Smash Brothers Brawl" that is coming out on March 9th (because the actual game will come out in America that day) are going to be pretty good. If there is an item it will go after it and stuff. Lots of stuff of course is from archmage's Merry Smashmas though it is not a remix. I literally put the blocks together and spent my work. Though I bet it will be better. Not sure if it will have the scrolling part with the zooming out though I am working on it. This is how the main stage will look, Basically the main battle field.

             |\                                 _                                           ___________
             | |                             /   \       ___________           | |    | |    | |
             | |      ________     /       \                                      | |    _______
             | |                           \       /                                      | |    | |    | |
          ________________________________________________________
         |_______________________________________________________|

Eh, looks horrible, it is hard to make pictures.


http://i.imgur.com/WBkM2QQ.png

Offline

 

#9 2008-02-07 11:59:17

boisvert
Scratcher
Registered: 2007-06-21
Posts: 25

Re: Enemy AI Scripts

Well, a permanently running loop would constantly check for relative position, direction...

Scratch could easily use a "heuristics" point counting AI for decision making, example:

Set the heuristics:
================

forever
  if distance to sprite < 50
     set "choose to move" to 10
else
     set "choose to move" to 5

  if speed of sprite > 10
     change "choose to move" by -7
else
     change "choose to move" by 7
end forever

Use the heuristics:
================

forever
  if "choose to move" > 8
     point to sprite
     move forward
end forever

You can have variables for a lot of decision making - choose to move, to shoot, pick a direction rather than another. By tweaking the factors that affect the decision (the points added or taken away), you arrive at very subtle difference of behaviour. That's how the Pacman ghosts do it.

Enjoy
Charles

Offline

 

#10 2008-02-07 12:03:19

boisvert
Scratcher
Registered: 2007-06-21
Posts: 25

Re: Enemy AI Scripts

Err, my heuristics are rubbish, try again:

boisvert wrote:

forever

  if distance to sprite < 50
     set "choose to move" to 10
else
     set "choose to move" to 5

  if speed of sprite > 10
     change "choose to move" by -7

end forever

Like that "choose to move" is positive if the sprite is near and slow, negative otherwise.

Offline

 

#11 2008-09-16 01:28:40

Makh
Scratcher
Registered: 2008-09-16
Posts: 1

Re: Enemy AI Scripts

Can someone tell me how to make spaceships shoot at each other.

Offline

 

#12 2008-09-16 04:58:07

Paddle2See
Scratch Team
Registered: 2007-10-27
Posts: 1000+

Re: Enemy AI Scripts

Makh wrote:

Can someone tell me how to make spaceships shoot at each other.

It all depends on how complicated you want to get...are you trying to make a computer opponent that can fire back at you?  Or something simpler like a video where you just need the ships to shoot at each other?

Have you already figured out how to make bullets shoot?  You will need to know how to do that first.  Here's a shooting tutorial you might want to look at...

http://scratch.mit.edu/projects/News-guy/263160


http://i39.tinypic.com/2nav6o7.gif

Offline

 

#13 2008-10-11 12:34:22

RPGmasterSilent
Scratcher
Registered: 2008-10-04
Posts: 22

Re: Enemy AI Scripts

how do i do the thing if the guy is within range he attacks?


Lachos can dios! Whatever that means...

Offline

 

#14 2008-10-11 12:57:18

archmage
Scratcher
Registered: 2007-05-18
Posts: 1000+

Re: Enemy AI Scripts

RPGmasterSilent wrote:

how do i do the thing if the guy is within range he attacks?

if abs( hero x position - enemy x position)<attackRange
broadcast fight

something like this


Hi, I am Archmage coder extraordinaire. I do Scratch,pascal,java,php,html, AS2 and AS3. Leave me a message if you want coding advice. Also check out my personal website, lots of good stuff about web development, Flash, and Scratch (v1 and v2) !

Offline

 

#15 2008-10-11 18:30:39

jwiens
Scratcher
Registered: 2007-10-17
Posts: 39

Re: Enemy AI Scripts

i think archmage should look at my burst limit demo game. i used programming similar to his ideas. it works alright but once you set it to higher difficulties you have to be careful on delay time.

Offline

 

#16 2009-07-15 12:01:33

alfredsawhoop
Scratcher
Registered: 2009-07-14
Posts: 2

Re: Enemy AI Scripts

dude no mother flipping way


swagg surfin hop up out tha benze with muh swag on take a look and the mirror and say whats up yeahhh!!!!!!!!!!! get money!!

Offline

 

#17 2009-07-15 12:44:16

Oneandonly
Scratcher
Registered: 2009-02-07
Posts: 100+

Re: Enemy AI Scripts

I think I done this kind of thing before... Alright... maybe try
<when green flag clicked>
<forever>
<if>  <( x position of player <<> x position of enemy )>
<move( -However many )steps>
<end>
<if> <( x position of player <>> x position of enemy )>
<move( How ever many steps )steps>
<end>
It's that or the opposite way.

Last edited by Oneandonly (2009-07-15 12:45:21)

Offline

 

#18 2010-04-28 12:56:18

Ziggy215
Scratcher
Registered: 2010-04-28
Posts: 9

Re: Enemy AI Scripts

Thanks a lot, I've been looking everywhere for this, and I needed it for my Stick Figher Sereies, can I use it?

Offline

 

#19 2010-04-28 15:37:30

AmoebaMan
Scratcher
Registered: 2009-01-26
Posts: 500+

Re: Enemy AI Scripts

never use the term AI.  the proper term is CPU behavioral replicant.  artificial intelligence is impossible to create.  unless you're god.


http://i942.photobucket.com/albums/ad269/RyanScathe/AmoebaMan.png

Offline

 

#20 2011-05-29 18:55:04

robocos987
Scratcher
Registered: 2011-04-08
Posts: 3

Re: Enemy AI Scripts

I know how to make enemy AL scripts. My game "Super Scratch Brawl" contains these scripts.

Offline

 

Board footer