Collision Detection - How do I detect where a ball intersects a plane?

Software: Away3D 4.x

Jason Latta, Newbie
Posted: 26 August 2011 07:22 PM   Total Posts: 16

I am creating a kinect driven game using the Away3D v4.  When the user plays the game they will pull back a ball in a slingshot (angry birds, first person) and shoot at a target. The target is just a plane with a bullseye texture.

How should I detect where the ball hits target?

   

faroer, Newbie
Posted: 27 August 2011 07:18 PM   Total Posts: 18   [ # 1 ]

Perhaps you can try to use the HitTest method

Something like this:

stage.addEventListener(Event.ENTER_FRAMEcollisionDetection);

function 
collisionDetection(ev:event)
{
if(ball.hitTestObject(plane))
  
{
    trace
("Collision Detected");
  
}
else
  
{
    trace
("No Collision Detected");
  
}

 

   

Jason Latta, Newbie
Posted: 27 August 2011 08:50 PM   Total Posts: 16   [ # 2 ]

HitTestObject doesn’t work on Away3D objects that I am aware of unless I overlooked something.

   

Avatar
Alexander Seifert, Moderator
Posted: 05 September 2011 12:19 PM   Total Posts: 129   [ # 3 ]

Perhaps, as long as it’s just a sphere and plane intersection, all you need to check is the distance between the sphere’s center and the surface of the plane. The math behind that is trivial and can be googled easily. However, walking down that lane you’ll end up requiring a high frame rate so that you can do the collision check at a high frequency as not to miss any intersecting, depending on how big the sphere is. That is the point where you’d typically go an research books about collision detection and/or physics libraries. As for the latter of the two, it is their job to detect and resolve collisions properly. Have you had a look at AwayPhysics yet?

Cheers!
Alex

 Signature 
signature_image

http://www.deltastrike.org

   

Avatar
theMightyAtom, Sr. Member
Posted: 05 September 2011 05:14 PM   Total Posts: 669   [ # 4 ]

Presumably you’ll be calculating the position of the ball via a formula (angle, velocity, gravity), so you probably know exactly where it is each frame? You can even calculate the intersection long before the impact if you are using a formula for trajectory.

If you put in a test when the balls z position is greater or equal to (>=) the targets z pos, you will catch all collisions (or otherwise) even if the z positions don’t intersect exactly, due to low frame rate, high velocity, etc.

psuedo code:

if( ball.>= plane.z){
   
if(ball.planeMinX && ball.planeMaxX && ball.planeMinY && ball.planeMaxY){
     
//hit!
    // from the balls x,y you can then make a mark on the target using it's UV coordinates
   
}

 

   

Jason Latta, Newbie
Posted: 05 September 2011 06:33 PM   Total Posts: 16   [ # 5 ]

I am basically doing that now and it is working pretty good.  If time allows I will give the physics engine ago. My deadline is this Friday and I have to tackle some other issues first with the UI and Kinect.  I will post a video of it working when it is ready. Since it is Kinect based it won’t be playable online.

Thanks for the input.

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X