How to make enemies spawn and approach player in radius

hi, i’m making an adventure game and i’m trying to implement enemies. I want them to spawn at a specific area and attack the player when they get too close. I have the code for both of them and they work separately but when i put them together it doesn’t work, Please help.

Link for the game:https://arcade.makecode.com/S06666-01683-09087-05960

1 Like

Heres a fix it doesn’t have a radius or the radius is to big but the enemies spawn and move to the player
https://arcade.makecode.com/S16597-31483-75401-89839

1 Like

Thanks!

Someone recently asked a similar question!

You can use this extension which has this built-in block to get distance between sprites (and lots of other handy stuff :star_struck:)

image

As for your own code, the reason it’s not working is because you called the radius check function only in the “On start” block! If you put it in a “Forever” block, it will work like this!

1 Like

Basic follow system


The follow code should be on a game update block so the sprites are constantly checking if the player is near.


More complex follow

I like to use the distance block on the enemy sprite follow speed so it’s always close to the player


and also some collision so the snakes don’t overlap each other
The 2 number parameters control the velocity and the acceleration of the enemy sprites when they overlap with each other (how fast they collide away from each other)

3 Likes

@Luke you should look up boids! does a similar thing

2 Likes

i’ve heard of that! I think if i can wrap my head around vectors in blocks i might be able to give it a shot

How do you change the distance for when the follow event is triggered?

1 Like

if distance > variable then set follow speed to 0
variable = distance at which enemy will follow

1 Like

Thanks dude, I appreciate it .

1 Like