Laser collision

Member
Posts: 196
Joined: 2002.04
Post: #1
I'm starting a new post for this since the other one is getting kind of long. Here's the dowload code:
http://www.geocities.com/jonwhitejamos/laser.sit

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.

Thanks,
Iceman
Member
Posts: 304
Joined: 2002.04
Post: #2
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);

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;

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);

hth,
Codemattic
Member
Posts: 196
Joined: 2002.04
Post: #3
Thanks it looks so much cooler now. 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:
http://www.geocities.com/jonwhitejamos/laser2.sit

Thanks,
Icey
Member
Posts: 196
Joined: 2002.04
Post: #4
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: http://www.geocities.com/jonwhitejamos/Laser3.sit

Thanks,
Iceman