Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Enemy Spawning Code
- mr-dash332
-
21 posts
Enemy Spawning Code
So I want to make the enemy only spawn when the screen is at a certain position. I need it to be a range of positions. If you click on my enemy sprite I have were the range of Spawning should start. I can clarify something if you need me to.
Project:
https://scratch.mit.edu/projects/976234831/editor/
Project:
https://scratch.mit.edu/projects/976234831/editor/
- PhiPhenomenon
-
500+ posts
Enemy Spawning Code
You gave where the enemies should start spawning, but you don't have a limit to where they should stop. Should the enemies only spawn when the players are inside of the first room?
Anyway, here's what you can do with the limits you have right now:
Anyway, here's what you can do with the limits you have right now:
when green flag clicked
forever
if <(Enemy SX) > [287]> then
show
else
hide
end
end
- mr-dash332
-
21 posts
Enemy Spawning Code
Yeah they should only spawn one enemy one that red circle, but I want the enemy to also despawn if you get far enough away. In the variable “Enemy SX”
The “S” stands for screen and the "X stands for the X position of that enemy on the screen. So I want it to only spawn if the player can see the red circle. The red circle is just so I know where the enemy is going to spawn.
The “S” stands for screen and the "X stands for the X position of that enemy on the screen. So I want it to only spawn if the player can see the red circle. The red circle is just so I know where the enemy is going to spawn.
- PhiPhenomenon
-
500+ posts
Enemy Spawning Code
How far away should the player be? Can you give bounds to when the enemy should despawn? Yeah they should only spawn one enemy one that red circle, but I want the enemy to also despawn if you get far enough away.
- mr-dash332
-
21 posts
Enemy Spawning Code
If the player leaves the room the enemy should despawn. I'm also thinking of moving the enemy to the center if it would make the spawning and despawning easier. (Also thank you so much for the help)
- PhiPhenomenon
-
500+ posts
Enemy Spawning Code
The room where the enemy spawns has exits only on the left and right, so the Enemy SY variable won't need to be used. I approximate the left side of the room is SX = 700 and the right side is SX = 200. Of course, if you want to use your original number (SX = 287), you can do that too.

when green flag clicked
forever
if <<(Enemy SX) > [200]> and <(Enemy SX) < [700]>> then
show
else
hide
end
end
(Also thank you so much for the help)

Last edited by PhiPhenomenon (March 6, 2024 23:46:51)
- mr-dash332
-
21 posts
Enemy Spawning Code
How would I make it scroll with the background while going after the player
- PhiPhenomenon
-
500+ posts
Enemy Spawning Code
What do you mean? Currently, it's just a circle that shows up on the screen. How would I make it scroll with the background while going after the player
- mr-dash332
-
21 posts
Enemy Spawning Code
I want it to go to the red circle and forever go after the player. I want it to move at half the speed as the player.
- PhiPhenomenon
-
500+ posts
Enemy Spawning Code
Your enemy sprite variables seem to be inconsistent with how the other variables, like Player X and SCROLL X, work. I'm going to make two new variables Enemy X and Enemy Y so it'll be easier to work with.

Sorry for the big image. Exported directly from the editor because I didn't wanna write scratchblocks. You can change how fast the enemy moves by editing the numbers next to the sine and cosine.
I want it to go to the red circle and forever go after the player. I want it to move at half the speed as the player.

Sorry for the big image. Exported directly from the editor because I didn't wanna write scratchblocks. You can change how fast the enemy moves by editing the numbers next to the sine and cosine.
- mr-dash332
-
21 posts
Enemy Spawning Code
I'm doing this on my school computer so I cant even see the image. Don't know why they have it blacked out
- mr-dash332
-
21 posts
Enemy Spawning Code
I understand being too lazy to write scratch blocks.
- grasblok
-
1 post
Enemy Spawning Code
qferyegfeiujtvgFYadugqh2diudfghizds rhuygu skiJW
Respwan if stRTA PRAESEad
rehagygv
enter
wehgyuahhhjhcjka
<trdtrcjnbgc>
yt<yftsdftusrdfg765sdftrdrasduetsresxcrr424356.com.yt.com>
Respwan if stRTA PRAESEad
rehagygv
enter
wehgyuahhhjhcjka
<trdtrcjnbgc>
yt<yftsdftusrdfg765sdftrdrasduetsresxcrr424356.com.yt.com>
- michaeljackson1365
-
1000+ posts
Enemy Spawning Code
Sorry, you've necroposted. qferyegfeiujtvgFYadugqh2diudfghizds rhuygu skiJW
Respwan if stRTA PRAESEad
rehagygv
enter
wehgyuahhhjhcjka
<trdtrcjnbgc>
yt<yftsdftusrdfg765sdftrdrasduetsresxcrr424356.com.yt.com>
- Discussion Forums
- » Help with Scripts
-
» Enemy Spawning Code