Discuss Scratch

squelz
Scratcher
100+ posts

clones and projectiles

is there a way to create multiple clones (via function) that can fire its own projectile (with more than one at a time) where each projectile has its own type of “stats”, like dmg etc, that moves either linearly, or in a parabola on one axis

project:
https://scratch.mit.edu/projects/1296571519/
g6g6g66g6g
Scratcher
100+ posts

clones and projectiles

You can store different possible types of clones in a list that stores values like the name of that kind of clone, its health, speed, type of “gun” it uses, and so on for each different clone type. The guns can themselves be stored in a separate list, storing its name, rate of fire, damage, number of pellets per shot, and bullet type. The bullets can go in a third list, but it won't come with many stats since it probably just stores the costume and the way it moves.

When listing the “type of gun” and “bullet type”, you use the number that points to the first item of the matching type you're looking for. e.g. Say the guns list looks like this:

  1. sniper
  2. 1
  3. 300
  4. 1
  5. shotgun
  6. 2
  7. 25
  8. 8

If your clone wants to use a shotgun, then for its “gun type” it should have the value “5”.

Do you need help with specific steps like how shooting would work in a script, or how to do a parabola shot (i'm not sure what that means actually), or how to do clone-clone collision when the clones have different stats?
squelz
Scratcher
100+ posts

clones and projectiles

g6g6g66g6g wrote:

You can store different possible types of clones in a list that stores values like the name of that kind of clone, its health, speed, type of “gun” it uses, and so on for each different clone type. The guns can themselves be stored in a separate list, storing its name, rate of fire, damage, number of pellets per shot, and bullet type. The bullets can go in a third list, but it won't come with many stats since it probably just stores the costume and the way it moves.

When listing the “type of gun” and “bullet type”, you use the number that points to the first item of the matching type you're looking for. e.g. Say the guns list looks like this:

  1. sniper
  2. 1
  3. 300
  4. 1
  5. shotgun
  6. 2
  7. 25
  8. 8

If your clone wants to use a shotgun, then for its “gun type” it should have the value “5”.

Do you need help with specific steps like how shooting would work in a script, or how to do a parabola shot (i'm not sure what that means actually), or how to do clone-clone collision when the clones have different stats?


sorry if i didnt say it right but, i dont know how to have multiple clones, which each has a clone of a projectile sprite (with its stats) that goes to a specific clone, that moves in a direction that can hit the player sprite and delete itself

it would be nice if i could see you remix the project and let me know what you were trying to say
deck26
Scratcher
1000+ posts

clones and projectiles

The best idea is to make the projectiles clones of the same sprite as the gun. Use a cloneID system to do this - see https://scratch.mit.edu/projects/111228685

You can then just use local (this sprite only) variables for attributes like damage. Normal x and y velocities and gravity are normally enough for a sensible trajectory.
squelz
Scratcher
100+ posts

clones and projectiles

deck26 wrote:

The best idea is to make the projectiles clones of the same sprite as the gun. Use a cloneID system to do this - see https://scratch.mit.edu/projects/111228685

You can then just use local (this sprite only) variables for attributes like damage. Normal x and y velocities and gravity are normally enough for a sensible trajectory.

wait, cloned clones keeps the original's variables?? thats new to me
this should work, ty
deck26
Scratcher
1000+ posts

clones and projectiles

squelz wrote:

deck26 wrote:

The best idea is to make the projectiles clones of the same sprite as the gun. Use a cloneID system to do this - see https://scratch.mit.edu/projects/111228685

You can then just use local (this sprite only) variables for attributes like damage. Normal x and y velocities and gravity are normally enough for a sensible trajectory.

wait, cloned clones keeps the original's variables?? thats new to me
this should work, ty
That's the big advantage of this method - the cloned projectiles inherit the parent's position, direction etc.
squelz
Scratcher
100+ posts

clones and projectiles

deck26 wrote:

squelz wrote:

deck26 wrote:

The best idea is to make the projectiles clones of the same sprite as the gun. Use a cloneID system to do this - see https://scratch.mit.edu/projects/111228685

You can then just use local (this sprite only) variables for attributes like damage. Normal x and y velocities and gravity are normally enough for a sensible trajectory.

wait, cloned clones keeps the original's variables?? thats new to me
this should work, ty
That's the big advantage of this method - the cloned projectiles inherit the parent's position, direction etc.

i am currently trying to use this method, but im stumped trying to make different versions of projectiles and costumes in the same sprite (with different “stats” variables), like what if i wanted to use multiple costumes instead of one

if you could, can i get an example of this

Last edited by squelz (March 31, 2026 18:06:18)

g6g6g66g6g
Scratcher
100+ posts

clones and projectiles

Keep a list of stats for the clones and bullets like the one i mentioned above. Then when you're about to create the clone, use the list to set the relevant variables like speed, costume, type of clone (enemy or bullet) etc. then make the clone. at that point the clone runs a different script depending on whether it's a bullet or an enemy, which lets it use the relevant variables.

Here's a demo below. Let me know if it's unclear or if you're looking for something else.
DEMO
squelz
Scratcher
100+ posts

clones and projectiles

g6g6g66g6g wrote:

Keep a list of stats for the clones and bullets like the one i mentioned above. Then when you're about to create the clone, use the list to set the relevant variables like speed, costume, type of clone (enemy or bullet) etc. then make the clone. at that point the clone runs a different script depending on whether it's a bullet or an enemy, which lets it use the relevant variables.

Here's a demo below. Let me know if it's unclear or if you're looking for something else.
DEMO

thanks for the demo but im unsure if “touching ____” block works with clones and doesnt just use the sprite's variables, and i would like if you could remix this project in the enemies sprite within the function (ill edit the link in later), it would be nice if you could also explain the variables for index and the others, and also what the operators for the lists too
g6g6g66g6g
Scratcher
100+ posts

clones and projectiles

squelz wrote:

but im unsure if “touching ____” block works with clones and doesnt just use the sprite's variables

If you have a <touching [sprite 1]> block for example, it will return “true” if the current sprite is touching sprite 1 or any of its clones. It cannot tell the difference between clones and the original. I'm not sure how variables are related to the touching sprite sensing.

The “enemy index” in my project is just the first item in the “Enemy types” list for a certain enemy class. For example, let's say every enemy stores 2 things: Its costume name and its speed. Then an example list could look like:
  1. regular
  2. 2
  3. sniper
  4. 1
  5. shotgun
  6. 1.5
In this case you can see the “sniper” enemy has a speed of 1, because the list item after the costume name is the enemies speed. For this list the possible values for “enemy index” are 1, 3, and 5, because they are the first items for each new enemy type in the list. For any of those values 1, 3, 5, you get the costume name, and if you add 1, you get the speed. You can extend this logic to fit as many classes and properties as you need. Choose the enemy index for the enemy type you want, then that value gives you property A (e.g. costume) for that enemy type, adding 1 gives you property B (e.g. speed), adding 2 gives you property C, etc.

CodeSprinter123
Scratcher
76 posts

clones and projectiles

You can use a separate spaner costume: https://scratch.mit.edu/projects/1298514349/
squelz
Scratcher
100+ posts

clones and projectiles

g6g6g66g6g wrote:

squelz wrote:

but im unsure if “touching ____” block works with clones and doesnt just use the sprite's variables

If you have a <touching [sprite 1]> block for example, it will return “true” if the current sprite is touching sprite 1 or any of its clones. It cannot tell the difference between clones and the original. I'm not sure how variables are related to the touching sprite sensing.

The “enemy index” in my project is just the first item in the “Enemy types” list for a certain enemy class. For example, let's say every enemy stores 2 things: Its costume name and its speed. Then an example list could look like:
  1. regular
  2. 2
  3. sniper
  4. 1
  5. shotgun
  6. 1.5
In this case you can see the “sniper” enemy has a speed of 1, because the list item after the costume name is the enemies speed. For this list the possible values for “enemy index” are 1, 3, and 5, because they are the first items for each new enemy type in the list. For any of those values 1, 3, 5, you get the costume name, and if you add 1, you get the speed. You can extend this logic to fit as many classes and properties as you need. Choose the enemy index for the enemy type you want, then that value gives you property A (e.g. costume) for that enemy type, adding 1 gives you property B (e.g. speed), adding 2 gives you property C, etc.



ok so i do want to use the if touching block, is there a work around that could differentiate it from the original sprite and each individual clone?

Powered by DjangoBB