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

#1 2011-06-21 22:00:46

tonibbb
New Scratcher
Registered: 2011-06-21
Posts: 5

How do you bounce off something other than an edge or wall?

For a school assignment i have to make a game, i have finished everything except i cant make the ball bounce off the bar. Even my digital teacher cant figure it out, if you have any answers i need them desperatly  smile  thanks

Offline

 

#2 2011-06-21 22:03:39

Kileymeister
Scratcher
Registered: 2008-04-17
Posts: 1000+

Re: How do you bounce off something other than an edge or wall?

If you need it to just bounce up and down, you can use this in place of the "if on edge bounce" block:
http://i56.tinypic.com/11bn7ft.gif

Do you need it to bounce on all four sides?  If you do I can write a longer explanation.

Last edited by Kileymeister (2011-06-21 22:04:15)


I'm back, and showcasing two new* projects!  Click left or right on the image below to see!
http://img109.imageshack.us/img109/7905/part1l.pnghttp://img859.imageshack.us/img859/6417/part2bf.png

Offline

 

#3 2011-06-21 22:12:34

tonibbb
New Scratcher
Registered: 2011-06-21
Posts: 5

Re: How do you bounce off something other than an edge or wall?

Yes please it didnt work the way i wanted it to. Im trying to bounce the ball off a paddle, like the game pong and it just moved to the side slighty but still went through the paddle?

Offline

 

#4 2011-06-21 22:14:48

Kileymeister
Scratcher
Registered: 2008-04-17
Posts: 1000+

Re: How do you bounce off something other than an edge or wall?

Perhaps it's repeatedly sensing the bar and turning.  Try this (make it a separate script):
http://i52.tinypic.com/wl4tw5.gif

Edit:  Is your paddle facing like this _ or like this | ?

Last edited by Kileymeister (2011-06-21 22:17:39)


I'm back, and showcasing two new* projects!  Click left or right on the image below to see!
http://img109.imageshack.us/img109/7905/part1l.pnghttp://img859.imageshack.us/img859/6417/part2bf.png

Offline

 

#5 2011-06-21 22:19:34

tonibbb
New Scratcher
Registered: 2011-06-21
Posts: 5

Re: How do you bounce off something other than an edge or wall?

It still didnt work, its still going back into the wall (bad guy) which is behind the paddle?

Offline

 

#6 2011-06-21 22:22:33

Kileymeister
Scratcher
Registered: 2008-04-17
Posts: 1000+

Re: How do you bounce off something other than an edge or wall?

Hm, maybe I think your paddle is facing a different direction.

Last time, try this:
http://i55.tinypic.com/25yxc3k.gif


I'm back, and showcasing two new* projects!  Click left or right on the image below to see!
http://img109.imageshack.us/img109/7905/part1l.pnghttp://img859.imageshack.us/img859/6417/part2bf.png

Offline

 

#7 2011-06-22 10:50:29

EdnaC
Scratcher
Registered: 2007-08-28
Posts: 100+

Re: How do you bounce off something other than an edge or wall?

Do you have a project posted on the Scratch site that we can look at?  It's hard to describe potential solutions without knowing how you are moving the "ball".

One possibility: 

I'll assume that your ball is traveling across the screen in response to a velocity variable, I'll call that "Vx".  And that the paddle moves up and down based on user input.  Each time the movement script loops thru, you would change the xposition of the ball by Vx, and look for a condition where the ball is 'hitting' the paddle.  You could test for this by checking to see how close the xposition of the ball is to the xposition of the paddle.  You would also want to check to see if the yposition of the paddle and ball are close enough to mean that the ball is "hitting" the paddle.

If  (xposition(ball)) > ((xposition(paddle)) - 5) AND (abs (ypostion (ball)) - (abs (yposition paddle) < 1/2(paddle width) then

set Vx to Vx - .5

You will have to fill in the 'paddle width' and decide how much to change the ball's velocity.  I suggested subtracting 5 from the paddle position to account for its thickness, you can adjust that number to suit. The ball can't go "thru" the paddle using this scheme, as anytime that it is to the right of the paddle, it's "Vx" variable will be decreased until it starts heading back to the left.

Offline

 

#8 2011-06-23 20:17:56

tonibbb
New Scratcher
Registered: 2011-06-21
Posts: 5

Re: How do you bounce off something other than an edge or wall?

Neither of them worked the ball is still going backwards into the wall/bad guy  sad

Offline

 

#9 2011-06-24 07:12:03

EdnaC
Scratcher
Registered: 2007-08-28
Posts: 100+

Re: How do you bounce off something other than an edge or wall?

If you can post a project on-line, there are people who will help figure out what the problem is.  "Doesn't work" doesn't tell us anything useful to give you assistance - I'm unclear on what you are trying to do.

Offline

 

#10 2011-06-24 20:38:50

tonibbb
New Scratcher
Registered: 2011-06-21
Posts: 5

Re: How do you bounce off something other than an edge or wall?

Dont worry I figured it out by going on to other questions answers, thanks anyways. Its up on my page if you want to see what I was trying to do (its not a very good game, it was my first thing on scratch so dont judge)

Offline

 

Board footer