iDevGames Forums
Laser collision - Printable Version

+- iDevGames Forums (
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Game Programming Fundamentals (/forum-7.html)
+--- Thread: Laser collision (/thread-7633.html)

Laser collision - Iceman - Aug 6, 2002 02:16 PM

I'm starting a new post for this since the other one is getting kind of long. Here's the dowload code:

What I'm having trouble with is that when I run laser[j].y -45; It rotates and doesn't work properly with the distance collision:
distance = sqrt(((laser[j].x - xRock) * (laser[j].x - xRock)) + (((laser[j].y - 45) - yRock) *
((laser[j].y - 45) - yRock)));

try the GL_POINTS that I added in the "laserStruct" code to see what I'm talking about.


Laser collision - codemattic - Aug 7, 2002 05:27 AM

No wonder you are struggling to find this bug! Because there *isnt* one. You have created a frictionless world, and in a frictionless world when you shoot, the projectile gets its velocity from both its initial launch velocity and from the velocity of the ship that launches it. So from the ship's view - if the ship is moving at any steady velocity - the view of the projectile moving away always looks the same. If your ship is not moving, or if its moving fast - from its point of view the event looks the same. Now if after you lauch the projectile and then suddenly change direction, the projectile should no longer seem to 'follow' you. However your shots go by so fast you never get to see that effect. I made a version where the shots moved very slowly - and I added a key to 'brake' the ship - and after I shot I would brake - and the shot did 'veer' away. So thats fine. If you dont want the shots to 'pace' you, in -initLaser change:

laser[index].xv = -xVect + 15.0 * sin(2 * M_PI * angle / 360.0);
laser[index].yv = -yVect + 15.0 * cos(2 * M_PI * angle / 360.0);

to read:

laser[index].xv = 15.0 * sin(2 * M_PI * angle / 360.0);
laser[index].yv = 15.0 * cos(2 * M_PI * angle / 360.0);

anyway - the next thing to fix is how the shot starts from behind the ship. Start the shot ahead of the ship. So in -initLaser change:

laser[index].x = -xTrans;
laser[index].y = -yTrans;

to read:

laser[index].x = -xTrans + 45.0 * sin(2 * M_PI * angle / 360.0);
laser[index].y = -yTrans + 45.0 * cos(2 * M_PI * angle / 360.0);


Laser collision - Iceman - Aug 7, 2002 12:17 PM

Thanks it looks so much cooler nowGrin. I noticed that there was something wrong with the friction on the lasers, but I just thought it had something to do with the gluLookAt();. I still have the collision problem here's the code just run it and you should now see what I'm talking about:


Laser collision - Iceman - Aug 27, 2002 04:13 PM

Ok none of the links above work anymore but I think I may have figured it out. Could I use distance < 55 and check the angle of the laser to calulate the collision? And if so What would be the formula? Here's the code that I'm using now: