A Flash Developer Resource Site

Results 1 to 14 of 14

Thread: Another Bounce

  1. #1
    if($$>=1){Buy New Book}
    Join Date
    Sep 2002
    Posts
    17

    Another Bounce

    Hey everyone, i'm having some trouble on getting the bounce to go off in the right direction. This has got to be one of the most frequented questions. At any rate here is the code i'm using, what happens is the ball does in fact bounce in the right direction, but at a very slow speed. What should i multiply this by to make it stay in line with the correct speed?

    Code:
    onClipEvent(enterFrame){
    oldx = _x
    oldy = _y
    _x += xspeed
    _y += yspeed
    hyp = (oldy - _y)/(oldx-_x)
    
    if(hitTest(_root.wall)){
    	reflect = (2*_root.wall._rotation) - Math.atan(hyp)
    	xspeed = Math.cos(PI/180 * reflect)
    	yspeed = Math.sin(PI/180 * reflect)
    
    					  }
    }
    Last edited by Twisted_Mystic_7; 07-21-2003 at 02:42 AM.

  2. #2
    avatar free
    Join Date
    Jul 2002
    Location
    UK
    Posts
    835
    I'm, not sure what you meant with your last line: "What should i multiply this by to make it stay in line with the correct speed?" Multiply what by?

    You are doing one thing that could cause a bug. You are checking if you are in a wall, not if you are going to hit a wall. It's best to look before you leap If you're inside a wall then it's too late, sometimes your bounce code might not be able to get it back out of the wall.
    jonmack
    flash racer blog - advanced arcade racer development blog

  3. #3
    if($$>=1){Buy New Book}
    Join Date
    Sep 2002
    Posts
    17
    Sorry , this post was to much fluff.
    Last edited by Twisted_Mystic_7; 07-22-2003 at 02:22 AM.

  4. #4
    if($$>=1){Buy New Book}
    Join Date
    Sep 2002
    Posts
    17
    Ok, sorry for the convoluted question. basically what i need is to figure out how to make the object bounce off of a angled wall and leave with teh correct veloicty and angle. I'm totally stumped, i've been from this board to bit-101's. I'm just not getting it. Are there any good tutorials out there, or am i just over complicating the issue. Thanks.

  5. #5
    Junior Member
    Join Date
    Jul 2003
    Posts
    15

    hi there

    see this files
    Attached Files Attached Files
    LUSITANO

  6. #6
    if($$>=1){Buy New Book}
    Join Date
    Sep 2002
    Posts
    17
    I looked at the files, and while they are very interesting and well done, I must have missed the parts that are related to bouncing an object off of an angled wall. Would you mind explaining further?

  7. #7
    if($$>=1){Buy New Book}
    Join Date
    Sep 2002
    Posts
    17

    So Frustrated!

    ok, heres the code i'm using, it's been modified since the first few times, so now not only does it not bounce with the correct speed, but also at the wrong angle. So i submit this for your scruitny, any advice would be nice, but if no one can figure it out, please point me in the direction of the nearest angled bounce tutorial that (at least partially) explains some of the math behind it and how it works. enough rambleing, heres the code!

    Code:
    onClipEvent(load){
    xspeed = -10
    yspeed = 0
    PI = Math.PI
    
    }
    onClipEvent(enterFrame){
    
    _x += xspeed
    _y += yspeed
    
    
    //if(_root.wall.hitTest(_x,_y,true)){
    	if(hitTest(_root.wall)){
    	slope = Math.tan((oldy - _y)/(oldx-_x))
    	_x -= xspeed
    
    	ballAngle = Math.atan2(yspeed-_y, xstep-_x); 
    	wallAngle = _root.wall._rotation
    	bounceAngle = 2*wallAngle - slope
    	
    	x1 = Math.cos(bounceAngle)
    	y1 = Math.sin(bounceAngle)
    	xspeed = x1
    	yspeed = y1
    		
    					  }
    }

  8. #8
    banned by dp. I_am_TheFlasher's Avatar
    Join Date
    May 2003
    Posts
    801
    i as i said in the other thread about this same exact problem. "I found a tutorial for this. here ye go hope it helps, it should"

  9. #9
    if($$>=1){Buy New Book}
    Join Date
    Sep 2002
    Posts
    17
    I am familiar with Bit's site, but this problim involves an Angled wall, not a straight vertical or horizontal, those are simple, if it's vertical, reverse the xspeed, horizontal, reverse the y speed, but if it's at say...a 33 degree angle, what then?
    And, forgive me if i'm wrong, but it seems that you just did a blanket answer to several posts. Keith's tutorial is excellent for calcuating gravity, showing you how to "throw" things, and calculating friction, but it's not a tut for bounce, the only bounce it seems it covers is the bounce agains 0deg and 180deg walls. Honestally it does'nt seem like your actually trying to give a solution. But thank you for the attempt.
    Last edited by Twisted_Mystic_7; 07-24-2003 at 12:41 AM.

  10. #10
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,223
    One thing you should look after is different units of angles in Flash.For example line

    wallAngle = _root.wall._rotation

    gives you angle in degrees, thats from 0 to 360,
    but line

    x1 = Math.cos(bounceAngle)

    must be given angle in radians or it wont work.
    You can convert angles between degrees and radians with formula:
    angle_rad=angle_deg*(Math.PI/180)

  11. #11
    Junior Member
    Join Date
    Jul 2003
    Posts
    15
    Originally posted by Twisted_Mystic_7
    I looked at the files, and while they are very interesting and well done, I must have missed the parts that are related to bouncing an object off of an angled wall. Would you mind explaining further?
    Attached Files Attached Files
    LUSITANO

  12. #12
    Junior Member
    Join Date
    Jul 2003
    Posts
    15

    bounce again

    I think that you can put the same code that refers to the "floor", on the walls.

    Insted you use the yy coordinate you must use the xx coordinates.

    you can see other toturials of fisics in the site:

    www.kirupa.com


    ( sorry about my english but i'm portuguese)
    Attached Files Attached Files
    LUSITANO

  13. #13
    banned by dp. I_am_TheFlasher's Avatar
    Join Date
    May 2003
    Posts
    801
    oops sorry i probobly should have read your post more. Oh well i geuss i should learn some more math before entering the all mighty Math an Physics sector place thing

  14. #14
    if($$>=1){Buy New Book}
    Join Date
    Sep 2002
    Posts
    17

    Fixed it!!

    I found out what i was doing wrong!! It appears that if you read things litteral insted of saying "Hey i can use that", you can use them right. i'm using the equation set forth by Ed-Mack
    Code:
        
        R = 2W-P
        
        R = reflection
        W = Angle of the wall
        P = the path the ball is traveling in comparison to the horziontal
    the trouble was being caused by the fact that i was occasionally uising the actual rotation, which included negitive numbers, but according to Ed-Macks post, the number must be between 0 - 360. I was'nt paying attention, and allowed neg numbers. I changed the code to

    Code:
       wall = Math.Abs(_root.wall._rotation)
    
    // Instead of
    
    // wall = _root.wall._rotation

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