dcsimg
A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Ball collision

  1. #1
    Senior Member
    Join Date
    Jan 2004
    Posts
    141

    Ball collision

    Hi all.

    I have a MC (a ball) with this AS on it:

    Code:
    onClipEvent (load) {
    	left = 2 + _width / 2;
    	right = 498 - _width / 2;
    	top = 3 + _height / 2;
    	bottom = 285 - _height / 2;
    	xspeed = random(3) + 1;
    	yspeed = random(3) + 1;
    }
    onClipEvent (enterFrame) {
    	_x = _x + xspeed;
    	_y = _y + yspeed;
    	if ( (_x <= left) or (_x >= right) ) {
    		xspeed *= -1;
    	}
    	if ( (_y <= top) or (_y >= bottom) ) {
    		yspeed *= -1;
    	}
    }
    This bounces the ball off each 'wall'. Can anybody tell me how to add more balls (using actionscript - ie not copying and pasting on the stage) and to make the balls bounce off eachother too?

    Thanks.

  2. #2
    Senior Member
    Join Date
    Jan 2004
    Posts
    141
    OK, I've got hold of this:

    http://www.blog.highub.com/actionscr...ck-and-rotate/

    which is pretty much what I want. I'm not great with the physics stuff, but can anyone tell me how to 'pump' more balls into the pack? Like a paintball gun, for example?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center