I really didn't think this would be hard but someone please help. I have a ball that I'd like to bounce as if it were in a pong game. The only difference, instead of bouncing of the edges it's bouncing off this big sprite surrounding the outside of the project. Help please?
Offline
AllButSimilar wrote:
I really didn't think this would be hard but someone please help. I have a ball that I'd like to bounce as if it were in a pong game. The only difference, instead of bouncing of the edges it's bouncing off this big sprite surrounding the outside of the project. Help please?
So you want a bouncing script that would mimic what the edge would normally do? Is your sprite using direction or x and y velocities?
DIRECTION
when gf clicked forever move (x) steps if <touching [big sprite v] ?> if <([abs v] of (x position)) > [200]> point in direction ((direction) * [-1]) else point in direction ((((direction) - (90)) * (-1)) + (90)) end end endThat should work...tell me if it doesn't.
when gf clicked forever change x by (x velocity) change y by (y velocity) if <touching [big sprite v] ?> if <([abs v] of (x position)) > [200]> set [x velocity v] to ((x velocity) * (-1)) else set [y velocity v] to ((y velocity) * (-1)) end end endThat should also work...
Last edited by JSO (2012-01-28 05:35:34)
Offline
the one i use and scratch used in sample pong is
when gf clicked forever if <touching [sprite]> point in direction < [180] - (direction) move [5] steps turn ccw <pick random [-20] to [20]> degrees
Offline
Here is a slightly fixed version of AtomicBawm3's scripts:
DIRECTION
when gf clicked forever move (x) steps if <touching [big sprite v]?> if <([abs v] of (x position)) > (200)> point in direction (<direction> * (-1)) else point in direction (<<<direction> - (90)> * (-1)> + (90)) end end endX, Y VELOCITIES
when gf clicked forever change x by (x velocity) change y by (y velocity) if <touching [big sprite v]?> if <([abs v] of (x position)) > (200)> set [x velocity] to <(x velocity) * (-1)> else set [y velocity] to <(y velocity) * (-1)> end end end
Last edited by Magnie (2012-01-27 21:12:56)
Offline
AtomicBawm3 wrote:
AllButSimilar wrote:
I really didn't think this would be hard but someone please help. I have a ball that I'd like to bounce as if it were in a pong game. The only difference, instead of bouncing of the edges it's bouncing off this big sprite surrounding the outside of the project. Help please?
So you want a bouncing script that would mimic what the edge would normally do? Is your sprite using direction or x and y velocities?
DIRECTIONwhen gf clicked forever move (x) steps if [touching [big sprite]] if <abs(x position) > [200]> point in direction (<direction> * [-1]) else point in direction ([[<direction> - [90]] * [-1]] + [90]) end end endThat should work...tell me if it doesn't.
X, Y VELOCITIESwhen gf clicked forever change x by (x velocity) change y by (y velocity) if [touching [big sprite]] if <abs(x position) > [200]> set [x velocity] to ((x velocity) * -1) else set [y velocity] to ((y velocity) * -1) end end endThat should also work...
Thanks so much for your help!
Offline
AtomicBawm3 wrote:
DIRECTION
when gf clicked forever move (x) steps if <touching [big sprite v]?> if <([abs v] of (x position)) > [200]> point in direction ((direction) * [-1]) else point in direction ((((direction) - (90)) * (-1)) + (90)) end end endX, Y VELOCITIESwhen gf clicked forever change x by (x velocity) change y by (y velocity) if <touching [big sprite v]?> if <([abs v] of (x position)) > [200]> set [x velocity v] to ((x velocity) * (-1)) else set [y velocity v] to ((y velocity) * (-1)) end end end
Fixed scripts.
Offline
Magnie wrote:
Here is a slightly fixed version of AtomicBawm3's scripts:
DIRECTIONwhen gf clicked forever move (x) steps if <touching [big sprite v]?> if <([abs v] of (x position)) > (200)> point in direction (<direction> * (-1)) else point in direction (<<<direction> - (90)> * (-1)> + (90)) end end endX, Y VELOCITIESwhen gf clicked forever change x by (x velocity) change y by (y velocity) if <touching [big sprite v]?> if <([abs v] of (x position)) > (200)> set [x velocity] to <(x velocity) * (-1)> else set [y velocity] to <(y velocity) * (-1)> end end end
Thanks!
Offline
AllButSimilar wrote:
I really didn't think this would be hard but someone please help. I have a ball that I'd like to bounce as if it were in a pong game. The only difference, instead of bouncing of the edges it's bouncing off this big sprite surrounding the outside of the project. Help please?
Try this script:
when gf clicked forever if <touching big sprite> point in direction <pick random (0) to (360)> end
Offline
UltraScratcher1 wrote:
AllButSimilar wrote:
I really didn't think this would be hard but someone please help. I have a ball that I'd like to bounce as if it were in a pong game. The only difference, instead of bouncing of the edges it's bouncing off this big sprite surrounding the outside of the project. Help please?
Try this script:
when gf clicked forever if <touching big sprite> point in direction <pick random (0) to (360)> end
Well, first, you would have to add a move block and second, random direction means it can continue moving into the big sprite.
Offline
UltraScratcher1 wrote:
AllButSimilar wrote:
I really didn't think this would be hard but someone please help. I have a ball that I'd like to bounce as if it were in a pong game. The only difference, instead of bouncing of the edges it's bouncing off this big sprite surrounding the outside of the project. Help please?
Try this script:
when clickedforever if touching big spritepoint in direction pick random 0 to 360
Well, first, you would have to add a move block and second, random direction means it can continue moving into the big sprite.
Well, I don't think it works
Offline
Refer to Pong 4 sided extreme http://scratch.mit.edu/projects/chongyian/2536065
Offline