dcsimg
A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: Ball collision - hitTest based?

  1. #1
    Member
    Join Date
    Oct 2004
    Posts
    57

    Ball collision - hitTest based?

    Do anyone have a code that makes a ball bounce realistic with hitTest(x,y,true)? I would need that, and I've tried to make it for one year now.

    Please help!

  2. #2
    Banned
    Join Date
    Dec 2006
    Posts
    43
    for the hittest detection in a ball
    you must
    ps. the point in the ball must be in the center

    detect=(floor.hittest(ball._x+ball.width*0.5,ball. _y,true))||(floor.hittest(ball._x-ball.width*0.5,ball._y,true))||(floor.hittest(ball ._y+ball.height*0.5,ball._x,true))||(floor.hittest (ball._y-ball.height*0.5,ball._x,true))

    if(detect){
    //invert speeds of the ball
    }

    don`t forget the ball always has a little force going down
    Last edited by insanedoom; 03-24-2007 at 12:42 PM.

  3. #3
    Member
    Join Date
    Oct 2004
    Posts
    57
    Not exacly that I meant. I meant ball bouncing like THIS:
    http://www.harveycartel.org/metanet/...tB_demo04.html

    ... based on hitTest. Is it possible?

  4. #4
    Pixel Artéést chriso20's Avatar
    Join Date
    Apr 2003
    Location
    Notts, UK
    Posts
    325
    you could use trigonometry instead?

    then the balls would be able to bouce off each other correctly and it'd all be contained in the same code.

    how are you with trig?

  5. #5
    Pixel Artéést chriso20's Avatar
    Join Date
    Apr 2003
    Location
    Notts, UK
    Posts
    325
    i've done a quick demo of collision with trigonometry.

    here you go.


    to get the collisions or rather the bounces realistic, you'l need to look at the angle ball B is to A, then find the angle ball A's path is (left right, no up/down is 90 degrees) then use some maths to calculate the new angle then from that work out the co ordinate ratios (amount moving x and y) based on a set speed.

    i was trying to do it then realised i have my own work to do! lol good luck!
    Attached Files Attached Files

  6. #6
    Member
    Join Date
    Oct 2004
    Posts
    57
    Thanks, but that's not what I need. I know how to make ball vs ball collision.
    I want to know how I can make this[http://www.harveycartel.org/metanet...utB_demo04.html] with hitTest - ball vs that kind of ground.
    Last edited by Pattt; 04-12-2007 at 08:27 AM.

  7. #7
    Junior Member
    Join Date
    Sep 2005
    Posts
    15
    Ever find a solution to this?

    I was thinking of finding the tangent of the colliding surfaces and the angle between them for deflection.

    Any ideas on how this can be done?

  8. #8

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