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

#1 2012-07-02 13:06:48

DoowNimajneb
New Scratcher
Registered: 2012-06-27
Posts: 65

One at a time!!, URGENT!!!

I am making a carnival game (Will be called Roll 'em in! if you want to play on it when its done), and I need a coin sprite to point in a random direction. I know how to make it point in a random direction, but if I use send the coin to a wall, I need it to point towards a random direction every time it touches it, but not so it wont stop doing it.
I cant use 'forever if' block because if it touches it, it keep pointing in a random direction continually.
I cant use the 'if' block because it only makes the coin point in a random direction once and if it touches it again, it won't do it.
PLEASE HELP!!! THIS HAS TO BE DONE BY NEXT MONDAY!!!
I will be happy to answer any solutions, suggestions, questions or anything else,
Thanks!!

Offline

 

#2 2012-07-02 13:11:48

powerpoint56
Scratcher
Registered: 2012-04-19
Posts: 500+

Re: One at a time!!, URGENT!!!

Maybe something like this?

when gf clicked
forever
move //whatever way you want it to move
if <touching [edge/wall v]?>
point in direction (pick random (-179) to (179))
end
end
If this isn't what you meant or doesn't work, just let me know, and I'll be happy to help!  smile

Last edited by powerpoint56 (2012-07-02 13:13:44)


http://i48.tinypic.com/2072ctw.gif

Offline

 

#3 2012-07-04 02:45:54

DoowNimajneb
New Scratcher
Registered: 2012-06-27
Posts: 65

Re: One at a time!!, URGENT!!!

Hi Powerpoint,
Sorry, this doesn't work because the coin is always moving and I don't need that, I can already sort that problem out, I just need it to point in a random direction as it either just points once or when it touches a wall, points in  a random direction and does that forever.   PLEASE HELP!! THIS HAS TO BE DONE BY NEXT MONDAY!!!

Offline

 

#4 2012-07-04 02:59:28

SciTecCf
Scratcher
Registered: 2011-11-23
Posts: 1000+

Re: One at a time!!, URGENT!!!

If you want it to bounce off, just avoid turning altogether.

You will need 2 variables. One called XVel and another one called YVel. You will also need to separate your walls so that the walls at the top and bottom are a separate sprite.

Now, this script:

when gf clicked
go to x: (0) y: (0)
point in direction (pick random (-180) to (180))
move (4) steps //Adjust this number to adjust coin speed.
set [XVel v] to (x position)
set [YVel v] to (y position)
forever
 if <touching [wallstopandbottom v]?>
  set [YVel v] to ((YVel) * (-1))
  repeat until <not <touching [walltopandbottom v]?>>
   change x by (XVel)
   change y by (YVel)
  end
 end
 if <touching [wallssides v]?>
  set [XVel v] to ((XVel) * (-1))
  repeat until <not <touching [wallssides v]?>>
   change x by (XVel)
   change y by (YVel)
  end
 end
 change x by (XVel)
 change y by (YVel)
end

Last edited by SciTecCf (2012-07-04 03:19:27)


http://bit.ly/LCZEJRhttp://bit.ly/LSONcOhttp://bit.ly/LF3vIc
http://trinary.site40.net/images/scratchrank.php?username=SciTecCf&amp;display=small

Offline

 

#5 2012-07-04 03:26:16

daniel_j
Scratcher
Registered: 2012-05-22
Posts: 100+

Re: One at a time!!, URGENT!!!

SciTecCf wrote:

If you want it to bounce off, just avoid turning altogether.

You will need 2 variables. One called XVel and another one called YVel. You will also need to separate your walls so that the walls at the top and bottom are a separate sprite.

Now, this script:

when gf clicked
go to x: (0) y: (0)
point in direction (pick random (-180) to (180))
move (4) steps //Adjust this number to adjust coin speed.
set [XVel v] to (x position)
set [YVel v] to (y position)
forever
 if <touching [wallstopandbottom v]?>
  set [YVel v] to ((YVel) * (-1))
  repeat until <not <touching [walltopandbottom v]?>>
   change x by (XVel)
   change y by (YVel)
  end
 end
 if <touching [wallssides v]?>
  set [XVel v] to ((XVel) * (-1))
  repeat until <not <touching [wallssides v]?>>
   change x by (XVel)
   change y by (YVel)
  end
 end
 change x by (XVel)
 change y by (YVel)
end

ScitecCf, I have been trying to help him for a while now, his problem is that all his coins move, hen only 1 is suppose to, This has been posted atleast 3 times now.. lol check out the project, I think you could fix it, I couldn't!
Dan


http://i50.tinypic.com/2dhgnsx.jpg

Offline

 

#6 2012-07-04 11:37:35

DoowNimajneb
New Scratcher
Registered: 2012-06-27
Posts: 65

Re: One at a time!!, URGENT!!!

But it needs to turn, not bounce, And the 'wall', a sprite that is actually in the middle of the screen, not the wall on the outside of when you're creating a project...
the link to the glitched project is:
http://scratch.mit.edu/projects/DoowNimajneb/2647353
the board that is smaller than the rest of the sprites is not the glitch, download and the board will be fixed like its supposed to.
The glitch is with the coin... try it and youll see...

Offline

 

Board footer