Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Clones shooting projectiles
- bambamom
-
3 posts
Clones shooting projectiles
I've been making a new game, a simple shooter, mostly for the purpose of learning scratch. Its been going well, and there aren't too many bugs, but there is one serious problem. I have an enemy who keeps a safe distance from you and shoots at you, but there is a problem with the projectiles. Because this enemy is a clone, the bullet comes from the side of the screen, where I have the original copy hidden. When the clones open fire, the bullets come from the side of the screen, not the enemies. The separate sprite for the projectile does not know which units are clones, and spawns from the original.
How do I differentiate clones from each other, so that a different sprite can tell them apart, and interact with them separately?
How do I differentiate clones from each other, so that a different sprite can tell them apart, and interact with them separately?
- deck26
-
1000+ posts
Clones shooting projectiles
Have a local variable CloneID which is changed (by the calling script) each time you create a clone. You can then check the value when doing anything with that clone. You can also use lists to store the x/y positions of the clones so you know where each one is. Each clone can tell if it is touching a sprite so you should be able to do what you want.
- bambamom
-
3 posts
Clones shooting projectiles
Have a local variable CloneID which is changed (by the calling script) each time you create a clone. You can then check the value when doing anything with that clone. You can also use lists to store the x/y positions of the clones so you know where each one is. Each clone can tell if it is touching a sprite so you should be able to do what you want.
I don't get what you are trying to say (I don't know what a calling script is, and google does not seem to yield an answer). I want to have clones shoot projectiles, and I sort of acheived this with two variables of the X and Y coordinates of the clones. BUT, that only works with one clone at a time. Could you explain how a CloneID changed by the calling script would work?
- deck26
-
1000+ posts
Clones shooting projectiles
By the calling script I meant the script that creates the clone. If you have
So that's how you keep track of the positions of the clones.
I'll look at the next stage in another post once I've had chance to think about it.
with CloneID as a local variable then each clone gets a unique ID number. If you also have
then you've created lists to hold the x,y positions for the clones. So if CloneID=5 then item 5 of x-list will be the x-position of the clone. Obviously as the clone moves around you need to replace the items in the lists with the current values.
So that's how you keep track of the positions of the clones.
I'll look at the next stage in another post once I've had chance to think about it.
- deck26
-
1000+ posts
Clones shooting projectiles
So how do we handle the firing. You don't say if they only fire when within a certain distance or all the time. I'll go for the latter for simplicity.
So in the bullet sprite you refer to each clone in turn. NB the x-list and y-list in my previous post need to be visible to all sprites.
You don't necessarily need the firex and firey variables; I just thought it made the explanation easier.
So in the bullet sprite you refer to each clone in turn. NB the x-list and y-list in my previous post need to be visible to all sprites.
You don't necessarily need the firex and firey variables; I just thought it made the explanation easier.
- joshyrooster
-
3 posts
Clones shooting projectiles
now im having the problem that i cant make the bullets go in the direction of my clone 

- deck26
-
1000+ posts
Clones shooting projectiles
Please don't practice Scratchblocks in a topic like this - there's a sticky topic at the top of the forum dedicated to trying out Scratchblocks. now im having the problem that i cant make the bullets go in the direction of my clone
You should really start your own topic. The easiest way to handle bullets is to make them clones of the thing firing them (even if they are also clones) so they inherit the direction and position.
- LokoCoffee
-
3 posts
Clones shooting projectiles
So, you dont NEED firex and firey, so what do I put there instead ( This is from 2015 but I'm having the same problem ) So how do we handle the firing. You don't say if they only fire when within a certain distance or all the time. I'll go for the latter for simplicity.
So in the bullet sprite you refer to each clone in turn. NB the x-list and y-list in my previous post need to be visible to all sprites.
You don't necessarily need the firex and firey variables; I just thought it made the explanation easier.
Last edited by LokoCoffee (March 13, 2021 15:21:35)
- ninjaMAR
-
1000+ posts
Clones shooting projectiles
So, you dont NEED firex and firey, so what do I put there instead ( This is from 2015 but I'm having the same problem ) So how do we handle the firing. You don't say if they only fire when within a certain distance or all the time. I'll go for the latter for simplicity.
So in the bullet sprite you refer to each clone in turn. NB the x-list and y-list in my previous post need to be visible to all sprites.
You don't necessarily need the firex and firey variables; I just thought it made the explanation easier.
Please don't I don't understand the list thingnecropost. If your having the same problem, make a new topic
- LokoCoffee
-
3 posts
Clones shooting projectiles
sorry I did not know thatSo, you dont NEED firex and firey, so what do I put there instead ( This is from 2015 but I'm having the same problem ) So how do we handle the firing. You don't say if they only fire when within a certain distance or all the time. I'll go for the latter for simplicity.
So in the bullet sprite you refer to each clone in turn. NB the x-list and y-list in my previous post need to be visible to all sprites.
You don't necessarily need the firex and firey variables; I just thought it made the explanation easier.Please don't I don't understand the list thingnecropost. If your having the same problem, make a new topic
- Scratch-Bytes
-
12 posts
Clones shooting projectiles
You can also do this by the enemies temporarily setting an ‘I am a bullet’ variable, and spawning a clone of themselves, then setting it back.
It does mean your enemy code now has to act like an enemy, and a bullet but if everything runs from a single ‘when I start as a clone’ cap, it's not too bad to just do an ‘if I am a bullet … else …’ block.
Unfortunately it's not easy to convince young scratchers that the (initially) much more complicated new-bullet-list clone message queue method is a better way than this hack.
It does mean your enemy code now has to act like an enemy, and a bullet but if everything runs from a single ‘when I start as a clone’ cap, it's not too bad to just do an ‘if I am a bullet … else …’ block.
Unfortunately it's not easy to convince young scratchers that the (initially) much more complicated new-bullet-list clone message queue method is a better way than this hack.
Last edited by Scratch-Bytes (Oct. 15, 2023 04:37:41)
- BladiPetrov
-
100+ posts
Clones shooting projectiles
I'll make this clear. I didn't understand anything above. OK so the enemies' code when shooting will be this:
The bullet's code will be:
The bullet's code will be:
- deck26
-
1000+ posts
Clones shooting projectiles
I'll make this clear. I didn't understand anything above. OK so the enemies' code when shooting will be this:Please create your own new topic - you can refer to this one if necessary. many people won't read as far as your post, just respond to the original question so having your own topic makes it more likely the responses are to your post.
The bullet's code will be:
- Discussion Forums
- » Help with Scripts
-
» Clones shooting projectiles