All right, so I am making a carnival game in scratch, and i am struggling on making the coin move in a random direction.
So far I have:
when I receive [broadcasted thing] Point in direction <Pick random (1) to (180)>The 'broadcasted thing' is just a name I gave a broadcast.
Offline
repeat until <touching [board v]?> move (2) steps endIt should show you it moving. You can change the 2 for a different number (higher moves faster).
Offline
you would do somthing like this
when I receive [broadcasted thing v] glide (1) secs to x: (Pick random (1) to (360)) y: (pick random (1) to (360)) wait until <touching [board v]?>This is an alternative to Scimonster script, his would work, but if you want a really smooth and consistant glide use this script
Last edited by daniel_j (2012-06-28 07:59:30)
Offline
daniel_j wrote:
you would do somthing like this
when I receive [broadcasted thing v] glide (1) secs to x: (Pick random (1) to (360)) y: (pick random (1) to (360)) wait until <touching [board v]?>This is a code you could use, sorry for my terrible scratch blocks xD
Fixed.
Offline
SciTecCf wrote:
daniel_j wrote:
you would do somthing like this
when I receive [broadcasted thing v] glide (1) secs to x: (Pick random (1) to (360)) y: (pick random (1) to (360)) wait until <touching [board v]?>This is a code you could use, sorry for my terrible scratch blocks xDFixed.
Thanks again SciTecCf xD huge help
Offline
scimonster wrote:
repeat until <touching [board v]?> move (2) steps endIt should show you it moving. You can change the 2 for a different number (higher moves faster).
Will this script move smoothly or will it appear jittery?
Also, how can I get this to work for multiple sprites because it needs to top if it hits one of seventeen sprites. I am not bothered if I will have to keep repeating the same script for different sprites, I just want to know if this will work (well).
Offline
DoowNimajneb wrote:
scimonster wrote:
repeat until <touching [board v]?> move (2) steps endIt should show you it moving. You can change the 2 for a different number (higher moves faster).Will this script move smoothly or will it appear jittery?
Also, how can I get this to work for multiple sprites because it needs to top if it hits one of seventeen sprites. I am not bothered if I will have to keep repeating the same script for different sprites, I just want to know if this will work (well).
It won't appear too jittery, but there's a better script to use if you're detecting 17 sprites.
If you make a list, for example called "SpriteList", add the names of all 17 sprites into the list, then do:
Offline
Thanks!
Look like this is going to work perfectly!
Thanks to everyone who helped me!
Offline
how do I request for the thread to be locked?
Offline
fg123 wrote:
It won't appear too jittery, but there's a better script to use if you're detecting 17 sprites.
If you make a list, for example called "SpriteList", add the names of all 17 sprites into the list, then do:
I'm afraid that won't work. The (any v) value just selects a random member from the list, rather than actually returning every member of the list. This would sometimes return true and sometimes return false if the object were touching another sprite. Sorry.
Last edited by amcerbu (2012-06-29 13:16:06)
Offline
Well then how can I get it to work then!
Offline
Sorry, meant to put ? Instead of !
Offline
amcerbu wrote:
fg123 wrote:
It won't appear too jittery, but there's a better script to use if you're detecting 17 sprites.
If you make a list, for example called "SpriteList", add the names of all 17 sprites into the list, then do:
http://img151.imageshack.us/img151/6812 … telist.gifI'm afraid that won't work. The (any v) value just selects a random member from the list, rather than actually returning every member of the list. This would sometimes return true and sometimes return false if the object were touching another sprite. Sorry.
Really, I recall that it worked back then. Let me test it...
EDIT: It doesn't select a random one, it actually iterates through the list at super speed.
It does do the detection though, so it works. Try it.
Last edited by fg123 (2012-06-29 17:23:57)
Offline
I did try it. Here's the link:
http://scratch.mit.edu/projects/ubrecma/2644346
Notice that, even when the red cat is touching another cat, the variable "flickers", depending on which member of the list the "item (any)" block has selected.
Offline
amcerbu wrote:
fg123 wrote:
It won't appear too jittery, but there's a better script to use if you're detecting 17 sprites.
If you make a list, for example called "SpriteList", add the names of all 17 sprites into the list, then do:
http://img151.imageshack.us/img151/6812 … telist.gifI'm afraid that won't work. The (any v) value just selects a random member from the list, rather than actually returning every member of the list. This would sometimes return true and sometimes return false if the object were touching another sprite. Sorry.
IF you're constantly looping over it then it gives a fairly useable result
Offline
^^Not really...
Let's say there are 100 objects on the screen, meaning 100 items in the list to check. The main object will move, and every frame, will check if it is touching a random 1 of these 100. That means that if it is actually touching a specific object, there is only a 1/100 (1%) chance that it will register collision with that object.
I don't think that this project will be using 100 sprites (maybe 15 is a reasonable guess) but that's still only about a 7% accuracy rate.
Last edited by amcerbu (2012-06-30 04:09:51)
Offline
just wondering (because these posts are going a little off-topic) Is there any other way to get my coin to stop if it hits one of 17 sprites without using scripts? Or can someone give me a definate/straight answer to whether I can use lists or not?
Thanks,
DoowNimajneb
Offline
I meant to say "instead of using lists" sorry!
Offline
Here is a script for your gliding coin:
when I receive [broadcasted thing v] repeat until <touching [board v]?> glide (1) secs to x: (Pick random (1) to (360)) y: (pick random (1) to (360)) end hideHere is a script to stop once it touches a coin:
when I receive [broadcasted thing v] forever if <touching [sprite v]?> hide
Last edited by daniel_j (2012-06-30 08:00:46)
Offline
I'm sorry, if you want to detect colision with multiple sprites at once, you have to do
repeat until <<touching [a sprite v]?> or <<touching [another sprite v]?> or <<touching [a third sprite v]?> or <<touching [yet another sprite v]?> or <<touching [one more sprite v]?> or <...>>>>>> stuffIf all the sprites you want to detect are the same colour, and nothing else is that colour, you can use
<touching color [#65de7a]?>block, but if not, you'll have to use the long one above. Perhaps a future version of scratch might have a way to group sprites together then have a
<touching sprite from group [ a group v]?>block, but the current version doesn't, so you'll have to use the above method.
Last edited by joefarebrother (2012-06-30 08:12:22)
Offline
amcerbu wrote:
^^Not really...
Let's say there are 100 objects on the screen, meaning 100 items in the list to check. The main object will move, and every frame, will check if it is touching a random 1 of these 100. That means that if it is actually touching a specific object, there is only a 1/100 (1%) chance that it will register collision with that object.
I don't think that this project will be using 100 sprites (maybe 15 is a reasonable guess) but that's still only about a 7% accuracy rate.
He said 17, so it does give a fairly usable result.
Because he's not doing any long script in the event, he's merely stopping movement.
Offline