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

#1 2011-05-09 22:40:37

bdn7
Scratcher
Registered: 2010-07-10
Posts: 100+

Multiple AI Sensors

I am making a game with artificial intelligence zombies, and have all of the direction and walking programmed. But the problem is that it is a platformer and the zombies can walk through walls. This wouldn't be a problem if I only had one, but I have lots. Too many to program individual sensors for each one. How can I make lots of zombies that can't walk through walls without me having to program each one's sensors?


http://i.imgur.com/Q7PiV.png
That's right. My text is BLUE.

Offline

 

#2 2011-05-09 22:47:22

Nedron
Scratcher
Registered: 2010-12-16
Posts: 17

Re: Multiple AI Sensors

Pretty simple, actually. Make the script that adds the sensor onto one zombie, then drag that script into another zombie. It will copy itself into that other sprite (it will also stay on the zombie you put it on), so keep dragging that script onto each of the zombies. It may take a while, but it's faster than making new scripts for each and every zombie. Hope this helps.


Play Epic Pong, the ONLY pong game with powerups!!!!! *Campaign is now out*
Play Now! It's in beta, so keep checking back for more awesome updates!!!

Offline

 

#3 2011-05-09 22:50:20

Necromaster
Scratcher
Registered: 2010-04-07
Posts: 1000+

Re: Multiple AI Sensors

Make a costume called sensor. Then "forever if touching <level> and <costume = sensor>, then do your sense script.  smile

Offline

 

#4 2011-05-10 17:50:02

bdn7
Scratcher
Registered: 2010-07-10
Posts: 100+

Re: Multiple AI Sensors

Nedron wrote:

Pretty simple, actually. Make the script that adds the sensor onto one zombie, then drag that script into another zombie. It will copy itself into that other sprite (it will also stay on the zombie you put it on), so keep dragging that script onto each of the zombies. It may take a while, but it's faster than making new scripts for each and every zombie. Hope this helps.

What would the script say?


http://i.imgur.com/Q7PiV.png
That's right. My text is BLUE.

Offline

 

#5 2011-05-10 17:52:22

bdn7
Scratcher
Registered: 2010-07-10
Posts: 100+

Re: Multiple AI Sensors

Necromaster wrote:

Make a costume called sensor. Then "forever if touching <level> and <costume = sensor>, then do your sense script.  smile

I tried that, but it wasn't working.


http://i.imgur.com/Q7PiV.png
That's right. My text is BLUE.

Offline

 

#6 2011-05-11 02:06:59

Nedron
Scratcher
Registered: 2010-12-16
Posts: 17

Re: Multiple AI Sensors

bdn7 wrote:

Nedron wrote:

Pretty simple, actually. Make the script that adds the sensor onto one zombie, then drag that script into another zombie. It will copy itself into that other sprite (it will also stay on the zombie you put it on), so keep dragging that script onto each of the zombies. It may take a while, but it's faster than making new scripts for each and every zombie. Hope this helps.

What would the script say?

You could make a purple dot (or a color of any dot that isn't being used), then make a on green flag click, forever if not color purple touching color (whatever the color of the walls are) and then the movement part. If you want them to face the other direction when hitting a wall, add another script that says on green flag click forever if color purple touching color (color of walls) point in direction direction minus 180 and you should get it (be sure to set the rotation setting to only points left and right so your zombie doesn't flip upside down). Hope this helps!!!  smile


Play Epic Pong, the ONLY pong game with powerups!!!!! *Campaign is now out*
Play Now! It's in beta, so keep checking back for more awesome updates!!!

Offline

 

#7 2011-05-11 07:22:46

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Multiple AI Sensors

This is a script that can be used to detect walls without a sensor costume, or sensor sprites.  It is the main character of the platformer, but by changing some of the conditionals you may be able to make it work.


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#8 2011-05-11 16:00:06

bdn7
Scratcher
Registered: 2010-07-10
Posts: 100+

Re: Multiple AI Sensors

MoreGamesNow wrote:

This is a script that can be used to detect walls without a sensor costume, or sensor sprites.  It is the main character of the platformer, but by changing some of the conditionals you may be able to make it work.

So would I make the zombies go in the opposite direction they would normally go, because the ground is also black and that would make it go the opposite direction?


http://i.imgur.com/Q7PiV.png
That's right. My text is BLUE.

Offline

 

#9 2011-05-11 17:44:29

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Multiple AI Sensors

Well, my script cancels movement out perfectly, so if you end up touching a wall, you're stuck.  What about this:

Code:

<when green flag clicked>
<forever>
<if>Zombie Wants to Go Right
     <change x by( 2 )>
<end>
<if>Zombie Wants to Go Left
     <change x by( -2 )>
<end>
<if><<  <not> <touching color[ black ]> >>
     <set{ PrivateVarG }to( 0 )>
     <change y by( -2 )>
     <if><touching color[ black ]>
          <set{ PrivateVarG }to( 1 )>
     <end>
     <change y by( 1 )>
     <if>
          <change y by( 1 )>
     <end>
<end>
<if><< Zombie wants to jump <and> <( <{ PrivateVarG }> <=> 1 )> >>
<set{ PrivateVari }to( 0 )>
<end>
<if><( <{ PrivateVari }> <<> 20 )>
     <change{ PrivateVari }by( 1 )>
     <change y by( 4 )>
     <if><touching color[ black ]>
     <set{ PrivateVari }to( 20 )>
     <change y by( -4 )>
     <end>
<end>

This is what my code used to be before I added velocity with the added conditionals that you'll need.  Both the variables are private for the zombie.


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#10 2011-05-11 18:11:21

bdn7
Scratcher
Registered: 2010-07-10
Posts: 100+

Re: Multiple AI Sensors

MoreGamesNow wrote:

Well, my script cancels movement out perfectly, so if you end up touching a wall, you're stuck.  What about this:

Code:

<when green flag clicked>
<forever>
<if>Zombie Wants to Go Right
     <change x by( 2 )>
<end>
<if>Zombie Wants to Go Left
     <change x by( -2 )>
<end>
<if><<  <not> <touching color[ black ]> >>
     <set{ PrivateVarG }to( 0 )>
     <change y by( -2 )>
     <if><touching color[ black ]>
          <set{ PrivateVarG }to( 1 )>
     <end>
     <change y by( 1 )>
     <if>
          <change y by( 1 )>
     <end>
<end>
<if><< Zombie wants to jump <and> <( <{ PrivateVarG }> <=> 1 )> >>
<set{ PrivateVari }to( 0 )>
<end>
<if><( <{ PrivateVari }> <<> 20 )>
     <change{ PrivateVari }by( 1 )>
     <change y by( 4 )>
     <if><touching color[ black ]>
     <set{ PrivateVari }to( 20 )>
     <change y by( -4 )>
     <end>
<end>

This is what my code used to be before I added velocity with the added conditionals that you'll need.  Both the variables are private for the zombie.

The problem isn't with jumping, it's with the zombie bumping into walls. I don't fully understand how that helps with the wall sensing.


http://i.imgur.com/Q7PiV.png
That's right. My text is BLUE.

Offline

 

#11 2011-05-12 16:15:06

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Multiple AI Sensors

This is the wall sensing part:

Code:

<if>Zombie Wants to Go Right
     <change x by( 3 )>
     <if><touching color[ black ]>
          <change x by( -3 )
     <end>
<end>
<if>Zombie Wants to Go Left
     <change x by( -3 )>
     <if><touching color[ black ]>
          <change x by( 3 )
     <end>
<end>

This means the zombie can't go through the color black, because he bounces right off of it.


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

Board footer