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

#1 2012-08-24 22:59:59

14darkcats
Scratcher
Registered: 2012-05-23
Posts: 12

deflections

I am making a puzzle game, and to complete each puzzle, you need to shoot an energy bolt, and have it deflect off of certain blocks. Does anyone know the formula or script to make something have generally the same function as the 'if on edge, bounce' block? Any help is greatly appreciated.


http://i48.tinypic.com/2dwb66g.jpg
maybe

Offline

 

#2 2012-08-25 16:13:21

plemon11
New Scratcher
Registered: 2012-07-16
Posts: 9

Re: deflections

The behaviour of on-edge bounce is simply:

<point in direction <(direction) * [-1]> >
Use either the current x/y position compared against your targets x/y position or a touching color/target block to detect when to switch directions.

Hopefully, this has pointed you in the right direction (pun totally intended.)

Phill

Offline

 

#3 2012-08-25 16:36:59

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: deflections

plemon11 wrote:

The behaviour of on-edge bounce is simply:

point in direction <(direction) * (-1)> 
Use either the current x/y position compared against your targets x/y position or a touching color/target block to detect when to switch directions.

Hopefully, this has pointed you in the right direction (pun totally intended.)

Phill

Fixed. Anyway, that is not how you make a bounce with vertical and horizontal surfaces. This is how you make a bounce with more types of surface:

if <touching [left or right side of block v]?>
 point in direction ((direction) * (-1))
end
if <touching [top or bottom side of block v]?>
 point in direction (((direction) * (-1)) + (180))
end
I hope that this helps!

Last edited by ErnieParke (2012-08-25 17:54:24)


http://i46.tinypic.com/35ismmc.png

Offline

 

#4 2012-08-25 17:39:28

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: deflections

ErnieParke wrote:

Fixed. Anyway, that is not how you make a bounce with every type of surface. This is how you make a bounce with every type of surface:

if <touching [left or right side of block v]?>
 point in direction ((direction) * (-1))
end
if <touching [top or bottom side of block v]?>
 point in direction (((direction) * (-1)) + (180))
end
I hope that this helps!

ErnieParke is correct.  A slight change that I'd make to the "top or bottom side" would be to make it "180-direction" instead of "-1*direction + 180", but that's pretty much just personal preference.  His script works fine  smile

Edit: if your walls that you're bouncing sprites off of aren't vertical and/or horizontal, it will get more complex.  It's still possible, but you have to know either the slope or the angle of both the wall and the "bouncing sprite"

Last edited by MoreGamesNow (2012-08-25 17:41:00)


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#5 2012-08-26 22:15:35

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: deflections

If it's any use, you can check out an old Pinball project of mine which uses "deflection formulas" (just different operations depending on slope) to calculate bounce angles.  Here's the project:
http://scratch.mit.edu/projects/amcerbu/1004827

EDIT: 600th post!

Last edited by amcerbu (2012-08-26 22:15:49)

Offline

 

#6 2012-08-27 13:10:16

14darkcats
Scratcher
Registered: 2012-05-23
Posts: 12

Re: deflections

thank you guys so much this will definitely help!


http://i48.tinypic.com/2dwb66g.jpg
maybe

Offline

 

Board footer