Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » How do I make an enemy on a game that has a mind of its own? (sort of)
- Tommy100
-
Scratcher
100+ posts
How do I make an enemy on a game that has a mind of its own? (sort of)
I'm making a game that is kind of like pac man. Except that you are not allowed to kill the enemies. And I was wondering how I make an enemy that kind of has a mind of its own. So it randomly goes around the maze. Except that I do not want it to go right through parts of the maze. I want it to go as it should so that when it goes around the maze is doesn't touch a wall. Please help me!
- DudmasterUltra
-
Scratcher
100+ posts
How do I make an enemy on a game that has a mind of its own? (sort of)
You can use the random block to create random numbers, and the if statement to tell which path it will take. Pac-Man ai is a little tougher than regular since they have to not go through walls. Maybe you figure something out using glide blocks and random
- CatScratchDeluxe
-
New Scratcher
11 posts
How do I make an enemy on a game that has a mind of its own? (sort of)
I'm pretty sure the enemies should have something like this;
when green flag clickedMake something else to make it avoid the walls like
forever
glide (pick random () to (10)) secs to x: (pick random () to (10)) y: (pick random () to (10))
end
when green flag clickedThe blank space should make it unable to go through the wall
if <touching color [#f0f]?> then
end
- Tommy100
-
Scratcher
100+ posts
How do I make an enemy on a game that has a mind of its own? (sort of)
You can use the random block to create random numbers, and the if statement to tell which path it will take. Pac-Man ai is a little tougher than regular since they have to not go through walls. Maybe you figure something out using glide blocks and randomI tried that but the problem is that I want levels too. And the levels have different pathways… So it would take a LONG TIME to do that! Any other suggestions?
- Tommy100
-
Scratcher
100+ posts
How do I make an enemy on a game that has a mind of its own? (sort of)
I'm pretty sure the enemies should have something like this;Thanks I will try that but I don't know if it will work. Everyone I'm still open for suggestions!when green flag clickedMake something else to make it avoid the walls like
forever
glide (pick random () to (10)) secs to x: (pick random () to (10)) y: (pick random () to (10))
endwhen green flag clickedThe blank space should make it unable to go through the wall
if <touching color [#f0f]?> then
end
- RichardStarbright
-
Scratcher
38 posts
How do I make an enemy on a game that has a mind of its own? (sort of)
See http://scratch.mit.edu/projects/23515861/ , it is a good example of a computer having a “mind of its own”
- excelguru
-
Scratcher
1000+ posts
How do I make an enemy on a game that has a mind of its own? (sort of)
Maybe something like this:
(Steps) //create this variable
repeat until <touching color [#f0f]
change y by (5)
End
change y by (-5)
forever
If <([x position v] of [player v])>(x position)>
Set [steps v] to (5)
Else
Set [steps v] to (-5)
End
repeat until <touching color [#f0f]>
change x by (steps)
End
change x by ((0)-(steps))
If <([y position v] of [player v])>(y position)>
Set [steps v] to (5)
Else
Set [steps v] to (-5)
End
repeat until <touching color [#f0f]>
change y by (steps)
End
change y by ((0)-(steps))
- deck26
-
Scratcher
1000+ posts
How do I make an enemy on a game that has a mind of its own? (sort of)
That's the sort of thing I think a grid system is useful for. I did a tutorial here http://scratch.mit.edu/projects/47150778/
- Harakou
-
Scratcher
1000+ posts
How do I make an enemy on a game that has a mind of its own? (sort of)
Maybe something like this:Thanks, but this thread is over half a year old - please check the date before posting! Closing this, but if the thread owner wants this open again, they can just report it and ask.(Steps) //create this variable
repeat until <touching color [#f0f]
change y by (5)
End
change y by (-5)
forever
If <([x position v] of [player v])>(x position)>
Set [steps v] to (5)
Else
Set [steps v] to (-5)
End
repeat until <touching color [#f0f]>
change x by (steps)
End
change x by ((0)-(steps))
If <([y position v] of [player v])>(y position)>
Set [steps v] to (5)
Else
Set [steps v] to (-5)
End
repeat until <touching color [#f0f]>
change y by (steps)
End
change y by ((0)-(steps))

- Discussion Forums
- » Help with Scripts
-
» How do I make an enemy on a game that has a mind of its own? (sort of)