This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2013-01-10 13:11:59

zleap
New Scratcher
Registered: 2011-06-20
Posts: 3

collision detection

Hi

I am trying to write a game where 2 balls bounce around the screen and you move a player ball to avoid touching the other 2 balls. (I can add more balls later)

http://scratch.mit.edu/projects/zleap/3028345

each time the user yellow ball touches a black ball the lives (or life variable) should decrement by 1

What actually happens is that this goes down 2 or 3 each time,

Just wondering what the best way round this was.

The options seem to be mainly "touching" so if sprite 3 is touching sprite 1 or 2 then live -1 or if colour is touching colour. 

clearly as they are touching for longer the lives goes down quicker

II need something like

if spirit3 touches sprite3 then life -1

then carry on with the sprite moving around rather then running the above several times.  It happens even if I move sprite 3 across the plane of sprite 1 or 2, 2 is a clone of 1.

I run a programming club so one of the young people made it so it uses a yellow ball rather than the mouse cursor.,

Offline

 

#2 2013-01-10 13:15:29

zleap
New Scratcher
Registered: 2011-06-20
Posts: 3

Re: collision detection

Thank you in advance for any help or suggestions.

Offline

 

#3 2013-01-10 15:51:56

chimoo5
New Scratcher
Registered: 2013-01-08
Posts: 18

Re: collision detection

The problem is that as long as you are touching the black ball you lose points like a leech. One cheap fast solution is to give the user a lets say 1 sec invincibility when you are hit to "recover".

wait (1) secs
So put this after you lose one point. I recommend this, because there would be nothing stopping the user from following the black ball once the user is hit and not lose any more points from that sprite (if you had your dream code). Then again I haven't tested the theory that the black is too fast for the user to actually follow.

If this doesn't suit you let me know I'll be happy to look into what you really want.

Offline

 

#4 2013-01-10 16:30:19

zleap
New Scratcher
Registered: 2011-06-20
Posts: 3

Re: collision detection

That works, thanks,  in fact I reduced the time to 0.5 and it works better, 

Thanks again

Paul

Offline

 

#5 2013-01-10 16:50:06

chimoo5
New Scratcher
Registered: 2013-01-08
Posts: 18

Re: collision detection

No problem glad it all worked out.

Offline

 

#6 2013-01-10 19:40:50

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: collision detection

It might be better to use the following script:

when gf clicked
forever
if <<touching [Ball1 v]?> or <touching [Ball2 v]?>>
change [Lives v] by (-1)
wait until <not<<touching[Ball1 v]?> or <touching [Ball2 v]?>>>
end
end

Last edited by amcerbu (2013-01-10 19:41:20)

Offline

 

#7 2013-01-11 18:47:40

fetchydog567
Scratcher
Registered: 2011-12-28
Posts: 500+

Re: collision detection

Why is two posts asking the same thing about this post that posts, and I put a post on about that, that my post, was your post which is the same post but a little bit less information in my post, which my post has less informantion but I figured it out on that post but there is more posts with more information on what this post is all about posts which is better than my post, than your post, so this this is your post, and my post, which got the same posts that post on your post and my post.

Nothing else.


http://www.minecraftanonymous.com/assets/banners/banner_51.pngJust a reminder I won't be on Scratch that much but I 'll still be here, so if i'm on something, I will be commenting back, okay! wink , PICO Team!!!!!!!!!!! SCRATCH DEADW!!! PICO HACK ACCOUTNTT@@

Offline

 

#8 2013-01-11 18:54:15

BLU_Spy
Scratcher
Registered: 2012-01-05
Posts: 1000+

Re: collision detection

fetchydog567 wrote:

Why is two posts asking the same thing about this post that posts, and I put a post on about that, that my post, was your post which is the same post but a little bit less information in my post, which my post has less informantion but I figured it out on that post but there is more posts with more information on what this post is all about posts which is better than my post, than your post, so this this is your post, and my post, which got the same posts that post on your post and my post.

Nothing else.

... o_o


I HAVE SWITCHED ACCOUNTS! My new username is NoxSpooth.

Offline

 

Board footer