Discuss Scratch

copiery
Scratcher
11 posts

Enemy Clones Can't Trigger Explosions

I have a problem in my wave/zombie game where one specific type of enemies “the Gembos” throw exploding balls at the player. However I don't know how to trigger the explosion since I have the enemies, the ball, and the explosion particles in different sprites(it's complicated). If anyone knows the answer pls comment here with an explanation(if you want).

https://scratch.mit.edu/projects/1391581345/ This is the game MUCH more info on the code inside. also the first enemy that spawns is a Gembo and I made it so YOU are also a Gembo. press the mouse to shoot the ball anywhere. this version of gembo is working so the enemy version of gembo should be just like this.

P.S. I've already made code for an explosion I just don't know how the weapon clone can trigger it.

Feel free to criticize anything in the game


I hate clones

Last edited by copiery (Yesterday 17:18:08)

ClarkeGhost
Scratcher
100+ posts

Enemy Clones Can't Trigger Explosions

The easiest way to trigger the explosion from a weapon clone when it's in a different sprite is to use a broadcast combined with two global variables (variables for “all sprites”).

Since clones delete themselves when they hit their target, they need to save their location right before they disappear so the explosion sprite knows where to go.

1. Create two global variables (for all sprites):
• Explosion X
• Explosion Y

2. In the Ball/Weapon Sprite:

Right before the clone deletes itself (when it touches the player or ground), save its current coordinates to those variables and fire off a broadcast:

if <touching [Player v] ?> then
set [Explosion X v] to (x position)
set [Explosion Y v] to (y position)
broadcast [spawn explosion v]
delete this clone
end

3. In the Explosion Particle Sprite:

Have it listen for that broadcast, jump to those saved coordinates, and make a clone of itself to run your explosion code:

when I receive [spawn explosion v]
go to x: (Explosion X) y: (Explosion Y)
create clone of [myself v]

This completely bypasses the separate sprite issue because global variables and broadcasts can be read by everything in your project.

Powered by DjangoBB