Pages: 1
Any help on this one would be great.
For some reason, my alien is in denial and refuses to admit it's been hit.
I've got a 'Repeat until touching' set to the bullet but the loop is only occasionally exited from. As a test I included a seperate forever loop on the alien that contantly checks if it's touched by the bullet, and if it is, it says "ouch"
Well the alien says ouch so it's definately recognising the bullet all of the time - so why won't it exit out of my 'repeat until touching bullet' loop?
Btw, the reason the x and y position is being controllled from the stage is because I need this mechanism to control another 30 or so aliens. Any advice would be great. Thanks
http://www.scratch.mit.edu/projects/scratchmoore/18734
Offline
Another thing you might try is this:
in bullet sprite
repeat until | <<<xpos is greater than (alien x - range)> and <xpos is lesser than (alien x-range)> and <y pos = alien y>
Touch complex, but it should work.
Another thing: scratch won't check to see if the boolean is true or false until after the enclosed blocks are run through.
Hope it helps.
Last edited by toontownmiser (2007-07-02 19:05:17)
Offline
The problem is that you are only checking the contact twice a second.
You probably want a loop that is doing the detecting with a tiny wait (maybe 0.05 seconds) and a separate loop for the movement. Your detection loop might look like
repeat until touching sprite1
wait 0.05 sec
set dead to 1
and the other loop might look like
set dead to 0
repeat until dead > 0
<movement code with waits>
Offline
Ahh - I'd made the incorrect assumption that it was constantly checking.
Thanks for both those answers. I'm back on track again.
Many thanks
Offline
If your alien is detecting just fine, you might be able to influence you bullet with a broadcast or variable change.
Offline
For Kevin's solution, I'd recommend "wait 0" in the test loop. The move command seems essentially instaneous (true??) - if one object passes through another, the "collision" can be missed even for a wait as small as 0.05 - see http://scratch.mit.edu/projects/DrJim/19015 (download to edit project to see problem).
Offline
I was assuming that the movement code used either a glide or a loop of moves separated by waits, so that the bullet and target would be guaranteed to be in contact for a known minimum amount of time. Without such a guarantee, even a forever loop that has no waits is not guaranteed to do the detection.
Offline
Yes the issue actually had to be solved in 2 places. The movement of the alien(s) had to be synchronised with the checking for contact, but also, I was hiding the bullet as soon as it contacted with anything green, so it needed to travel a little further sometimes to be registered.
It workes ok now and I've added another dozen aliens no problem, all of them die like troopers. Now to get them to shoot back and to build some shelters for the gun.
Thanks for your advice everyone.
Offline
Problem sorted now.
Here's the project if you're interested
http://scratch.mit.edu/projects/scratchmoore/20226
Offline
Pages: 1