Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » How To Prevent Sprites From Overlapping
- SamuraiNinjaBento
-
Scratcher
82 posts
How To Prevent Sprites From Overlapping
The “Cops” (in the code they are called “Ghost”) overlap and eventually form just 1 but I would like them to not overlap each other.
If you can help then here is the Project: https://scratch.mit.edu/projects/258079655/
If you can help then here is the Project: https://scratch.mit.edu/projects/258079655/
- kieranblackley
-
Scratcher
500+ posts
How To Prevent Sprites From Overlapping
Here is my best solution:
- kieranblackley
-
Scratcher
500+ posts
How To Prevent Sprites From Overlapping
It will require a few variables. For each variable in this little tutorial I will make you will need to tick the box that sets for this sprite only before pressing OK. This way that variable can only be used in one sprite and it will also save you typing out (variablename)(extraparttonotmakeitaduplicate).
When you make the variable and name it you will see the box. Just press the box and a tick will appear and you can then press ok.
In each of the ghost sprites make the variables oldx and oldy. BIG NOTICE: MAKE SURE YOU TICK THE FOR THIS SPRITE ONLY BOX! Next in each of the ghost sprites, make this script:

That should reduce the chance of them overlapping. What it will do is that when they detect that they are touching each other they will try to move away from each other by using the oldx and oldy variables. The script must be put in order otherwise it won't come out as expected.
Hope it works!
When you make the variable and name it you will see the box. Just press the box and a tick will appear and you can then press ok.
In each of the ghost sprites make the variables oldx and oldy. BIG NOTICE: MAKE SURE YOU TICK THE FOR THIS SPRITE ONLY BOX! Next in each of the ghost sprites, make this script:

That should reduce the chance of them overlapping. What it will do is that when they detect that they are touching each other they will try to move away from each other by using the oldx and oldy variables. The script must be put in order otherwise it won't come out as expected.
Hope it works!

- Discussion Forums
- » Help with Scripts
-
» How To Prevent Sprites From Overlapping

