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:
The 'broadcasted thing' is just a name I gave a broadcast.when I receivebroadcasted thingPoint in directionPick random1to180
Offline
It should show you it moving. You can change the 2 for a different number (higher moves faster).repeat untiltouchingboard ▼?move2steps
Offline
you would do somthing like this
This is an alternative to Scimonster script, his would work, but if you want a really smooth and consistant glide use this scriptwhen I receivebroadcasted thing ▼glide1secs to x:Pick randomy:1to360pick random1to360wait untiltouchingboard ▼?
Last edited by daniel_j (2012-06-28 07:59:30)
Offline
daniel_j wrote:
you would do somthing like this
This is a code you could use, sorry for my terrible scratch blocks xDwhen I receivebroadcasted thing ▼glide1secs to x:Pick randomy:1to360pick random1to360wait untiltouchingboard ▼?
Fixed.
Offline
SciTecCf wrote:
daniel_j wrote:
you would do somthing like this
This is a code you could use, sorry for my terrible scratch blocks xDwhen I receivebroadcasted thing ▼glide1secs to x:Pick randomy:1to360pick random1to360wait untiltouchingboard ▼?Fixed.
Thanks again SciTecCf xD huge help
Offline
scimonster wrote:
It should show you it moving. You can change the 2 for a different number (higher moves faster).repeat untiltouchingboard ▼?move2steps
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:
It should show you it moving. You can change the 2 for a different number (higher moves faster).repeat untiltouchingboard ▼?move2stepsWill 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:
Here is a script to stop once it touches a coin:when I receivebroadcasted thing ▼repeat untiltouchingboard ▼?glide1secs to x:Pick randomy:1to360pick random1to360hide
when I receivebroadcasted thing ▼foreveriftouchingsprite ▼?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
If all the sprites you want to detect are the same colour, and nothing else is that colour, you can userepeat untiltouchingora sprite ▼?touchingoranother sprite ▼?touchingora third sprite ▼?touchingoryet another sprite ▼?touchingorone more sprite ▼?...stuff
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 atouching color ?
block, but the current version doesn't, so you'll have to use the above method.touching sprite from groupa group ▼?
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