AS: Main, better then Google!
Related Topics:
AS: Movement - Basic
AS: Varials
AS:Math
AS: Conditions
Next Step:
AS: Platform game
Ok, in this tutorial I'll teach you how to make basic bouncing physics. It's pretty simple once you understand basic math and conditions in flash. My first real flash game used this in it, and by the end of this tutorial you will be able to make one too.
1.) Make a movieClip, i'd suggest a circle(my movieclip was 50x50). You dont have to name it. Make sure the center is on the bottom of the movieclip.
2.)Set the specifications of your objects "physic's" like how fast it falls, where to bounce, how much the ground will lower the speed. Heres mine:
onClipEvent (load) {
ySpeed = 0;
//starting fall speed of object
gravity =3;
//how fast the ySpeed rises, should be no higher then 3
bounce = .8;
//how much the speed decreases when for each bounce
ground = 350;
//where to bounce back
}
When the rest of the code is finished you should change the numbers around so they fit to your liking.
3.) Set up your main code.
onClipEvent (enterFrame) {
if (_y<ground) {
ySpeed += gravity;
} else if (ySpeed>gravity*4) {
//change 4 to a higher number if it doesnt work
_y = ground;
ySpeed *= -bounce;
} else {
ySpeed = 0;
_y = ground;
}
_y += ySpeed;
}
Basically what this does is check if the object is above the specified "ground", if it is then the speed at which it falls it increased. Otherwise, the speed is multiplied negatively, so it will move in the opposite direction.
So that the ball would'nt bounce as high after each bounce i multiplied it by a decimal less than 1(variable-"bounce").
you may be wondering what "else if (ySpeed>gravity*4)" is for. well it basically stops the balls from moving when it speed is really low. without that, the ball would bounce forever. It may have a little jerk at the end but its better than nothing.
and that is all you need for a bouncing ball!
But George, thats really boring!! that cant possibly be all! and endless flight sucks.
well now that you understand the basics, you can add on to it, and make a cool game with it. for instance add this right after _y+=ySpeed:
if (_x<0 || _x>550) {
xSpeed *= -1;
}
_x += xSpeed;
xSpeed *= .95;
and add this at the bottom:
onClipEvent (mouseDown) {
//when mouse is clicked
if (hitTest(_root._xmouse, _root._ymouse, true)) {
// if touching the mouse
xSpeed = (_x-_root._xmouse)/2;
_y--;
ySpeed = (_y-_root._ymouse-_height)/1.5;
}
}
you now have your very own kick-ups game!
i quit