I am wondering, what formula could I use to simulate the block that says "if touching edge, bounce"?
Offline
It's fairly simple, if you are using velocity variables to control your sprites movement. Then, if it is a left or right edge, just multiply the horizontal velocity by (-1) to change the sign. If it is a top of bottom edge, multiply the vertical velocity by (-1).
Offline
You will need to calculate which edge you are touching - so rather than using "if touching edge" use
If ABS(X)>239
> Point in direction (-1)*(direction)
> Repeat until ABS(X)<240
> > Move 5 (this part is to stop it from getting stuck)
If ABS(Y)>179
> Point in direction (180)-(direction)
> Repeat until ABS(Y)<180
> > Move 5 (this part is to stop it from getting stuck)
Enclose all that inside a loop, includeing "Move 5" at the start of the loop.
Example here:
http://scratch.mit.edu/projects/Mayhem/96405
Offline
If you are using "move __ steps" then the bounce is just a change of direction.
If you are bouncing off a vertical edge, then the direction change is
set direction to -direction
If you are bouncing off a horizontal edge, then the direction change is
set direction to 180-direction
Offline
Honestly I was going to use it so if a ball was to touch the side of a rectangle it would bounce in the correct direction rather than pick random -40 to 40. :@
Offline
My code can easily be adaped for that by changing the values that X and Y are checked against.
Offline