Discuss Scratch

sleepyheadd_
Scratcher
12 posts

PLEASE HELP ME FIX THE BUG WITH MY SCRIPT!! WILL REPLY FAST!!




hello everybody! this is the bullet collision script I've been tinkering with for the past few weeks.

the first screenshot is for the bullet sprite, for when it's detected to be touching the enemy.
the second screenshot is for the enemy clones, which detect the bullet.

however, sometimes a bullet colliding with an enemy will kill multiple enemies instead of the one being shot at, regardless of how far the enemies are from each other!

if somebody could skim through my code and identify a potential cause for this, I'd be eternally grateful, as i cannot see why it's doing this myself.
Woodfur
Scratcher
100+ posts

PLEASE HELP ME FIX THE BUG WITH MY SCRIPT!! WILL REPLY FAST!!

Not sure, this looks pretty good to me. Actually sharing your project would help though, not just for the full code, but to be able to experiment with how different changes affect it.

Am I missing something or would it be fine to just have the enemies detect <touching bullet?> Or at least check that first before going through all the work of iterating through the list, which might fix your problem.

Last edited by Woodfur (July 10, 2023 08:39:28)

sleepyheadd_
Scratcher
12 posts

PLEASE HELP ME FIX THE BUG WITH MY SCRIPT!! WILL REPLY FAST!!

Woodfur wrote:

Not sure, this looks pretty good to me. Actually sharing your project would help though, not just for the full code, but to be able to experiment with how different changes affect it.

Am I missing something or would it be fine to just have the enemies detect <touching bullet?> Or at least check that first before going through all the work of iterating through the list, which might fix your problem.

the touching bullet way of doing it isn't as consistent, i've found. if i make the bullet delete itself upon touching an enemy, and the enemy delete itself upon touching the bullet, it will most of the time result in either the enemy not detecting the bullet or the bullet not detecting the enemy.
sleepyheadd_
Scratcher
12 posts

PLEASE HELP ME FIX THE BUG WITH MY SCRIPT!! WILL REPLY FAST!!

Woodfur wrote:

Not sure, this looks pretty good to me. Actually sharing your project would help though, not just for the full code, but to be able to experiment with how different changes affect it.

Am I missing something or would it be fine to just have the enemies detect <touching bullet?> Or at least check that first before going through all the work of iterating through the list, which might fix your problem.

if i share the project would you be interested in giving the code a look?
Koamodo975
Scratcher
1000+ posts

PLEASE HELP ME FIX THE BUG WITH MY SCRIPT!! WILL REPLY FAST!!

sleepyheadd_ wrote:

Woodfur wrote:

Not sure, this looks pretty good to me. Actually sharing your project would help though, not just for the full code, but to be able to experiment with how different changes affect it.

Am I missing something or would it be fine to just have the enemies detect <touching bullet?> Or at least check that first before going through all the work of iterating through the list, which might fix your problem.

the touching bullet way of doing it isn't as consistent, i've found. if i make the bullet delete itself upon touching an enemy, and the enemy delete itself upon touching the bullet, it will most of the time result in either the enemy not detecting the bullet or the bullet not detecting the enemy.
If you add a ‘Wait 0.0001 secs’ block in the bullet clone script right before it deletes itself, then both the enemy and the bullet should delete.
sleepyheadd_
Scratcher
12 posts

PLEASE HELP ME FIX THE BUG WITH MY SCRIPT!! WILL REPLY FAST!!

Koamodo975 wrote:

sleepyheadd_ wrote:

Woodfur wrote:

Not sure, this looks pretty good to me. Actually sharing your project would help though, not just for the full code, but to be able to experiment with how different changes affect it.

Am I missing something or would it be fine to just have the enemies detect <touching bullet?> Or at least check that first before going through all the work of iterating through the list, which might fix your problem.

the touching bullet way of doing it isn't as consistent, i've found. if i make the bullet delete itself upon touching an enemy, and the enemy delete itself upon touching the bullet, it will most of the time result in either the enemy not detecting the bullet or the bullet not detecting the enemy.
If you add a ‘Wait 0.0001 secs’ block in the bullet clone script right before it deletes itself, then both the enemy and the bullet should delete.

I… can't believe that worked. I've been losing my mind trying to find a workaround and all i needed was one block. thank you so much

Powered by DjangoBB