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

#1 2013-03-31 09:27:33

walkalone666
New Scratcher
Registered: 2013-03-30
Posts: 8

how do you deflect?

i have a ball that moves down the screen. the background has little red blocks. i want to make it so if it comes near a block it deflects 10 steps to the right or left at random. i can get the ball to go inside the block with the touching colour block but i want it to deflect so it doesn't go inside the block

Offline

 

#2 2013-03-31 10:28:21

7734f
Scratcher
Registered: 2010-12-23
Posts: 500+

Re: how do you deflect?

Here, look at this, it will help you.


http://internetometer.com/image/38992.png   http://i37.tinypic.com/2qixx6c.png

Offline

 

#3 2013-03-31 11:00:08

xlk
Scratcher
Registered: 2013-03-18
Posts: 57

Re: how do you deflect?

when gf clicked
forever
 change y by ([-2]*[falling speed])
 if <touching color [#ff0000]>
  if <(random number between [0] and [1]) = (1)>
   change x by [10]
  else
   change x by [-10]
  end
 end
 change y by [falling speed]
end

Offline

 

#4 2013-03-31 11:10:33

walkalone666
New Scratcher
Registered: 2013-03-30
Posts: 8

Re: how do you deflect?

Apparently I need to make a which way block

Offline

 

#5 2013-03-31 11:33:29

xlk
Scratcher
Registered: 2013-03-18
Posts: 57

Re: how do you deflect?

to make it dodge, all you have to do is make it detect when it is above a red object. I do this by making it go down twice as far, checking if it' touching red, and if it is, randomly moving left or right 10 pixels. Then I compensate the "go down twice" by making it go up.

I have no idea what you mean by "which way" block, there is no such thing, except maybe a custom block in scratch2.0 or a hacked block.

Offline

 

#6 2013-03-31 11:39:25

walkalone666
New Scratcher
Registered: 2013-03-30
Posts: 8

Re: how do you deflect?

The which way has to be made in variables. I can marked the block by going to variables and centering new variable which way but I don't know how to use it.

Offline

 

#7 2013-03-31 13:11:18

xlk
Scratcher
Registered: 2013-03-18
Posts: 57

Re: how do you deflect?

oh, you mean the random number block? It's actually a green block, not an orange one, but scratchblocks get confused....

Offline

 

#8 2013-03-31 17:43:09

walkalone666
New Scratcher
Registered: 2013-03-30
Posts: 8

Re: how do you deflect?

This is what I've been told. There is a pyramid of red pegs on a background. I can get the ball to hit the peg and make a noise. I can get it go randomly go left or right but I don't understand the which way button (I can make it not sure how to use it)

The ball is no longer stopped by the peg, but is instead deflected 10 steps sideways, either left or right with an equal probability, chosen randomly depending on the result of the pick_random[]to[] block, before resuming its movement vertically downwards. Once again, y_position of Ball should not exceed -175.
The result of the pick_random[]to[] block should be stored in a new variable called whichWay which you must create.

Offline

 

#9 2013-04-01 10:30:47

walkalone666
New Scratcher
Registered: 2013-03-30
Posts: 8

Re: how do you deflect?

i've nearly done it. i can get the ball to move down the screen and if it goes onto a red peg it will move left or right at random. but i need it so the ball doesn't go into the peg, it deflects it before it has a chance to go inside

Offline

 

#10 2013-04-29 16:44:17

Paddle2See
Scratch Team
Registered: 2007-10-27
Posts: 1000+

Re: how do you deflect?

If this question is about a homework assignment for a class - please make sure that asking for help on the Scratch forums doesn't violate any agreements you have with the teaching institution.


http://i39.tinypic.com/2nav6o7.gif

Offline

 

Board footer