Pong

I am familiar with hit test, but how do you make a ball bounce off a wall with the same angle that it bounced on it with?\r\rex. it hits the wall at 45 degrees, and it bounces off the wall at 45 degrees\r\rThanks 4 your time!

You can see a bounce that way, but also as a change of speed. When the thing bounces against a vertical wall, the _x speed just turns negative.\r\rTry this, I’m sure you can make this work.\r\rpom 0]

yea, that’s only part of it, i think i need to make the angle negitive or something…MORE HELP NEEDED PLEASE!!!

put the following code in a movie clip’s object actions. make the main stage 400x400.\ronClipEvent (load) {\r&nbsp &nbsp &nbsp &nbsp nXmov = (Math.random()*5)+3;\r&nbsp &nbsp &nbsp &nbsp nYmov = (Math.random()*5)+3;\r}\ronClipEvent (mouseUp) {\r&nbsp &nbsp &nbsp &nbsp nXmov = (Math.random()*5)+3;\r&nbsp &nbsp &nbsp &nbsp nYmov = (Math.random()*5)+3;\r}\ronClipEvent (enterFrame) {\r&nbsp &nbsp &nbsp &nbsp if (_x+nXmov<10) {\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp _x = 10;\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp nXmov *= -1;\r&nbsp &nbsp &nbsp &nbsp } else if (_x+nXmov>390) {\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp _x = 390;\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp nXmov *= -1;\r&nbsp &nbsp &nbsp &nbsp }\r&nbsp &nbsp &nbsp &nbsp if (_y+nYmov<10) {\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp _y = 10;\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp nYmov *= -1;\r&nbsp &nbsp &nbsp &nbsp } else if (_y+nYmov>390) {\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp _y = 390;\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp nYmov *= -1;\r&nbsp &nbsp &nbsp &nbsp }\r&nbsp &nbsp &nbsp &nbsp _x += nXmov;\r&nbsp &nbsp &nbsp &nbsp _y += nYmov;\r}\r\revery time you click, the speed will change.\r:) \rjeremy

Sinf, you have a gift to use variable names that make your code look complicated !!\rTry this “light” version : draw a ball, turn it into a movie clip, and add the actions :

  onClipEvent (load) {\r\rspeedx = 5 ;\r\rspeedy = 3 ;\r\r}\r\ronClipEvent (enterFrame) {\r\rif (_x>250) {_x=250 ; speedx *=-1;}\r\relse if (_x<50) {_x=50 ; speedx *=-1;}\r\rif (_y>250) {_y=250 ; speedy *=-1;}\r\relse if (_y<50) {_y=50 ; speedy *=-1;}\r\r\r\r_x += speedx ;\r\r_y += speedy ;\r\r}

pom 0]

the problem with your code is that there is a possibility of an error where the clip will get ‘stuck’ bouncing in the general area of the border. flash has problems incrementing floating point numbers, so if your ‘speed’ was 5.05 you may encounter an error. also, if you are applying acceleration, or gravity, or other changes to the ‘speed’ then you will get an error more often than not when using your method.\ri used to do the exact same thing, and it worked fine as long as it was just a ball by itself and the ‘speed’ was always an integer, and it didn’t change.\r:) \rjeremy\r\rp.s. i use ‘mov’ for frame based movement, and ‘speed’ for time based movement.

Argghhh! You got me Austin Powers !\rOK, I agree, your code is better, no doubts about that. It’s just that I wanted to show something basic… I’ve been doing stuff with acceleration but never had any trouble with it. Interesting though. Thanks !\r\rpom 0]