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?
Offline
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.
Offline
Make a costume called sensor. Then "forever if touching <level> and <costume = sensor>, then do your sense script.
Offline
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?
Offline
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!!!
Offline
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.
Offline
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?
Offline
Well, my script cancels movement out perfectly, so if you end up touching a wall, you're stuck. What about this:
<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.
Offline
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.
Offline
This is the wall sensing part:
<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.
Offline