Discuss Scratch

Wyrlwynd
Scratcher
14 posts

hit detection issue

I've got everything right where I want it in this game:
Tesseract

except…occasionally, the missile you fire goes right through the enemy ship…there seems to be no rhyme or reason for the intermittent hit detection (I say this only because I can't find it. There's a definite chance it's simply beyond my current level of understanding.)

The enemy ships are sprites 22, 26-41,47-50
The missiles are sprites 23-25,31

Any help would be appreciated.
drmcw
Scratcher
1000+ posts

hit detection issue

Renaming the sprites may help…not with the problem but with trying to understand what is what! At first I assumed it was a cloning problem but seeing how many sprites you have made me think you don't use cloning but then in the code you do use cloning however not in a way I was expecting. In fact I'm not even sure cloning is doing anything here? I suspect the problem is similar to one I had where one sprite/clone was moving through another but the hit detection code didn't have time to run. First question would be why not have one missile sprite and clone it? They all seem to look the same so can't understand why you need them.
Wyrlwynd
Scratcher
14 posts

hit detection issue

I think what happened with the way I used cloning was a lack of understanding of how to effectively use clones in the first place. Looking back now I think I would create 1 enemy ship with a costume for each direction (and maybe an alternate color costume for variety as well) and create 1 missile with a costume for each direction of fire. I remember thinking I only wanted so many ships in any one direction at a time and I shied away from cloning for fear of overpopulating the screen.

The other issue I had previously had with another game (before cloning) was being able to fire a new missile while the first was still moving. I didn't want to make 80 kagillion sprites for missiles, so I knew I had to clone the missiles, but even now they don't fire as quickly as I'd like them to. Honestly, I'm not even sure they're operating like clones should. In your Galaga game, the missiles are ultra plentiful. I'd like a mine to spawn somewhere near that fast but not spawn so quickly that they make it too easy.

So I have a couple of questions (I'll leave the hit detection issue aside for now in favor of cleaning the code up):

1) I currently have a rng choose to spawn a bad guy. Then a 2nd rng tells it which direction to spawn in. For levels one and three, a counter prevents more than 3 or 4 ships in any one direction. Would it suffice to have the dual rngs have 1 sprite (w/ appropriate directional costumes) cloned and sent in the correct direction and then have the counter still prevent too many clones from being made in any one direction and then have the clone deleted when it either is hit or reaches the edge of the playfield? There will never be more than 16 clones (in level 3) onscreen at once. If that is feasible, should I have the “create a clone of ____” be in the block w/ the rng and just have the “When I start as a clone” headers on the enemy ship?

2) I think I did the missile cloning completely wrong, but I'm not sure how to fix it. Obviously, I want a missile to fire every time you press a, but it seems like it's waiting for a script to finish before it will create a new clone to fire. Not sure why it doesn't function more quickly, so any help there would be greatly appreciated as well.

drmcw
Scratcher
1000+ posts

hit detection issue

1) I know it's going to be obvious but what's an mg?

2) You just need one missile with appropriate costumes then when the a key is pressed set up the missile how you want e.g go to ship, set appropriate costume and direction etc then create clone. The quicker you do this the quicker this event will finish and enable another missile to be fired. Then when I start as a clone should then contain all the moving logic. What confused me with yours was that all the logic is in the missile sprite but very little in the when I start as a clone which implies the clone does nothing so in effect you're not really using cloning at all just multiple sprites.
dracae
Scratcher
1000+ posts

hit detection issue

drmcw wrote:

1) I know it's going to be obvious but what's an mg?

2) You just need one missile with appropriate costumes then when the a key is pressed set up the missile how you want e.g go to ship, set appropriate costume and direction etc then create clone. The quicker you do this the quicker this event will finish and enable another missile to be fired. Then when I start as a clone should then contain all the moving logic. What confused me with yours was that all the logic is in the missile sprite but very little in the when I start as a clone which implies the clone does nothing so in effect you're not really using cloning at all just multiple sprites.

1) He put rng = random number generator.

Powered by DjangoBB