Discuss Scratch

Toritoro_o
Scratcher
42 posts

Enemy keeps sticking and stacking on each other!

so when the enemy chase the player they all clash together and then stack on each other. how do i fix this? my game is at: https://scratch.mit.edu/projects/569422829/ btw
deck26
Scratcher
1000+ posts

Enemy keeps sticking and stacking on each other!

This is always going to happen if multiple objects are heading for the same point - they're always going to get closer together as they near a single point (the player). That's just basic mathematics.

If you want o avoid this you need to handle the movement of the enemies to prevent it. For example move the one nearest to the player first. Then move the second nearest if possible, moving part way if necessary and repeat until you've dealt with all the enemies. But if the player isn't moving this will end up with the enemies pretty much in a line one behind the other which might look strange. So you probably want to give them the option of moving slightly off the direct route.

So for each enemy you perhaps need to try moving in the obvious direction but if you can't move far enough in that direction go back to the starting position and try pointing 2 degrees clockwise and try that, then try 2 degrees anti-clockwise if that fails and so on, trying up to 20 degrees in each direction. That will need to be a custom block with no screen refresh to get the speed you need.

What you're aiming for is the best move for each clone in turn - ie which move gets them closest to the player.
Toritoro_o
Scratcher
42 posts

Enemy keeps sticking and stacking on each other!

deck26 wrote:

This is always going to happen if multiple objects are heading for the same point - they're always going to get closer together as they near a single point (the player). That's just basic mathematics.

If you want o avoid this you need to handle the movement of the enemies to prevent it. For example move the one nearest to the player first. Then move the second nearest if possible, moving part way if necessary and repeat until you've dealt with all the enemies. But if the player isn't moving this will end up with the enemies pretty much in a line one behind the other which might look strange. So you probably want to give them the option of moving slightly off the direct route.

So for each enemy you perhaps need to try moving in the obvious direction but if you can't move far enough in that direction go back to the starting position and try pointing 2 degrees clockwise and try that, then try 2 degrees anti-clockwise if that fails and so on, trying up to 20 degrees in each direction. That will need to be a custom block with no screen refresh to get the speed you need.

What you're aiming for is the best move for each clone in turn - ie which move gets them closest to the player.
so i make the enemy clones go slower depending on the order of the distance to the player ? is there any way to make the clones not clash into each other? i tried
<touching color [#ed5055] ?> but it didnt work
deck26
Scratcher
1000+ posts

Enemy keeps sticking and stacking on each other!

The touching sprite block works for the sprite and clones detecting each other.
Toritoro_o
Scratcher
42 posts

Enemy keeps sticking and stacking on each other!

deck26 wrote:

The touching sprite block works for the sprite and clones detecting each other.
How? i dont think theres a selection for that in the list of the the touching sprite block
deck26
Scratcher
1000+ posts

Enemy keeps sticking and stacking on each other!

If you want to detect touching spriteA you need to copy the touching block from another sprite after selecting spriteA in the drop-down. You can then get spriteA and it's clones to detect touching each other.
Toritoro_o
Scratcher
42 posts

Enemy keeps sticking and stacking on each other!

deck26 wrote:

If you want to detect touching spriteA you need to copy the touching block from another sprite after selecting spriteA in the drop-down. You can then get spriteA and it's clones to detect touching each other.
ill try that, but the enemies arent even showing up now, idk why
deck26
Scratcher
1000+ posts

Enemy keeps sticking and stacking on each other!

They seem OK to me.

Powered by DjangoBB