A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: Bouncing

  1. #1
    Mental Deficit Nionicle's Avatar
    Join Date
    Mar 2002
    Location
    Utah, Hyrum
    Posts
    1,348

    Bouncing

    Ok help is what i need
    I want this circle to go all bouncy off the edges of the circle and stuff.
    But it wont work
    here is the fla and thanks in advanced
    Attached Files Attached Files
    I can only postulate the probability of performing at a paramount level of perfection praised by the pulchritudinous paragon whose only practice is to preserve such a paradigm.

  2. #2
    I have 2 brains
    Join Date
    Oct 2000
    Location
    Rotterdam
    Posts
    184
    Well, I think the most basic way to do this is to use hitTest. Using four mc's at each border...
    But if you want something like pool of snooker, than you will have to use real math...

    Something like this:
    Code:
    xmov = 5;
    _root.onEnterFrame = function() {
    	ball._x += xmov;
    	if (ball.hitTest(wallRight)) {
    		xmov *= -1;
    	}
    	if (ball.hitTest(wallLeft)) {
    		xmov *= -1;
    	}
    };
    Last edited by bchew007; 12-28-2002 at 08:47 AM.

  3. #3
    Mental Deficit Nionicle's Avatar
    Join Date
    Mar 2002
    Location
    Utah, Hyrum
    Posts
    1,348
    hmmm
    i really want it bouncing inside a circle not a square.

    But thanx


    >...
    I didnt post this right away.

    I got it to do almost what i want.

    Except i want the balls to bounce at more of an angle.
    Please help.
    Attached Files Attached Files
    I can only postulate the probability of performing at a paramount level of perfection praised by the pulchritudinous paragon whose only practice is to preserve such a paradigm.

  4. #4
    I have 2 brains
    Join Date
    Oct 2000
    Location
    Rotterdam
    Posts
    184
    I see. You are no beginner no more.
    Oh, you want it in a circle...
    Cool .fla, want to try that too. But first I have to dig up my math knowlegde from college.

  5. #5
    Senior Member
    Join Date
    May 2001
    Posts
    1,838
    If you dont mind that the ball bounces before it really hits the circle, then the codes might help.

    I made a dummy movieClip, put in 0,0 point of the _root. Just for coordinate manipulation. Then the codes are modified here:
    Code:
    if (Math.sqrt((_root.circle._x-_x)*(_root.circle._x-_x)+(_root.circle._y-_y)*(_root.circle._y-_y))>radius) {
    	//ypos = (ypos+(Math.random())-.5)*-1;
    	//xpos = (xpos+(Math.random())-.5)*-1;
    	_x -= xpos;
    	_y -= ypos;
    	dummy = _root.dummy;
    	dummy._rotation = (180/Math.PI)*Math.atan2(_y-_root.circle._y, _x-_root.circle._x);
    	pt = {x:xpos, y:ypos};
    	dummy.globalToLocal(pt);
    	pt.x *= -1;
    	dummy.localToGlobal(pt);
    	ypos = pt.y;
    	xpos = pt.x;
    	_x += xpos;
    	_y += ypos;
    }

  6. #6
    Mental Deficit Nionicle's Avatar
    Join Date
    Mar 2002
    Location
    Utah, Hyrum
    Posts
    1,348
    wohhhhh
    local to global? do i look that smart?
    lol

    still not sure where to put that code? in frame one of main timeline?
    I can only postulate the probability of performing at a paramount level of perfection praised by the pulchritudinous paragon whose only practice is to preserve such a paradigm.

  7. #7
    Senior Member
    Join Date
    May 2001
    Posts
    1,838
    Here is the fla.
    Attached Files Attached Files

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