Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Gaming > Development Programming Algorithms > Collision detec...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 2 Topic 578 of 670
Post > Topic >>

Collision detection

by "Stainless" <stainless@[EMAIL PROTECTED] > Sep 11, 2006 at 03:18 PM

Hiy guys,

I am working on a game and I want my space craft to have 6 shields 
(front,front right, rear right, rear, etc.)

The problem is doing the collision detect, I have code which is fast for 
checking if the shields are hit at all but finding the angle of the 
collision is non trivial.

I basicly check a line against a circle with this code, this includes 
scaling code but don't worry about that, the circle has radius s

   // screen position of object
    x3=((list[i]->x/vs)*202)+202;
    y3=((list[i]->y/vs)*235)+235;

    x1=202;
    y1=235;                      // start point of line

    x2=202+(500*cos(a1));
    y2=235+(500*sin(a1));        // end point of line

    u =(x3 - x1)*(x2 - x1) + (y3 - y1)*(y2 - y1);
    u/=(x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1);
    if ((u>=0)&&(u<=1))
   {
         xi = x1 + u *(x2 - x1);
         yi = y1 + u *(y2 - y1);

         r=sqrt(((xi-x3)*(xi-x3))+((yi-y3)*(yi-y3)));
         if (r<=s)
         {
                // hit
         }
  }

I know I can get rid of the sqrt but the problem is a line intersects a 
circle at two points and I need to find out the first point impacted.




 2 Posts in Topic:
Collision detection
"Stainless" <  2006-09-11 15:18:07 
Re: Collision detection
"Stainless" <  2006-09-12 07:57:10 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Tue May 13 12:24:14 CDT 2008.