View Full Version : Need bouncing script...
gameskid
January 16th, 2004, 01:35 PM
Ok, I'm new to Flash gaming, but I need a code to have a ball 'bounce' off a wall then 'bounce' down the same wall. I tried _x = -_x ect and that didn't work. Help!:rd:
thoriphes
January 16th, 2004, 01:56 PM
here's a snippet of what you might need:
// declare these somewhere
rightwall = 550-ball._width/2;
leftwall = ball._width/2;
// put this in some loop
if (ball._x >= rightwall) {
ball._x = rightwall; // very important!
vel = -vel; // reverse direction ball is traveling
}
if (ball._x <= leftwall) {
ball._x = leftwall;
vel = -vel;
}
ball._x += vel;This code makes a ball, with velocity 'vel' bounce back and forth on the two vertical walls. The left/rightwall variables are the positions of the two walls with an offset to make the bounce seem more realistic (as opposed to a ball bouncing back when half of it is outside the wall).
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.