Advertisement

problem with sphere-based collision detection

Started by August 22, 2002 11:55 AM
4 comments, last by Alexandre Brien 22 years, 5 months ago
Ok yet another problem of mine =P I have a CBullet class for my bullets, my problem is that when I fire my weapon, Im hurting myself!! That is because im using sphere-based collision detection so the bullet is automatically in contact with the sphere when i fire it. I know that to avoid this I simply have to initialize the bullet position just out of the sphere, but Im wondering what would be the maths behind this operation?? Heres my code, should be enough to let you pro''s know what to do =P
  
CBullet *bullet = new CBullet;
bullet->pitch= camera->pitch;
bullet->direction = direction;
bullet->position = position;
position.y+=5.0f;  //if i dont do this, bullet hits weird.

bullet->forward = camera->lookAt.UnitVector();
bullet->AttachTo(terrain);
arsenal[weaponEquiped].ammunition -= 1;
  
Oh and also, it seems that when my bullet collides with a sphere, the dmg is done about 12 times. I really dont understand this because I automatically delete the bullet object when it collides with either CPlayer (me) or a CEnemy derived class. any idea what might cause this??
In Construction : http://www.gdev.org
Just make sure the bullet starts further than the sum of the two radii(your guy and the bullet). If not, just make sure that your guy''s sphere isn''t in the collision detection list.
Advertisement
ya thats kind of my question =P

wondering how to make it start further, I could just add a constant value to x and z but I want to reposition the bullet on the same trajectory line.
In Construction : http://www.gdev.org
You could just have a member variable in the bullet to say who fired it, and ignore collisions if they are with the firer. The 12x damage problem sounds like you are taking damage for every timestep that the bullet is inside a players sphere. Try stepping through with a debugger is all I can suggest... perhaps it isn''t getting deleted when you think. Actually if you want a bullet to give varying damage depending on how well aimed it was, you could scale the damage down but leave the collision how it is. I mean, if the bullet was heading directly for the enemy, it spends 12 timesteps inside the sphere, if it was a bit off target it might only spend 1-2 timesteps in the sphere. This way a good shot does more damage.
hey thats not a bad idea, I was thinking about generating a random ID number for each entity because I might have several enemies of the same type so I need a way to distinct them.
In Construction : http://www.gdev.org
quote:

"...generating a random ID number for each entity..."



this 


There''s your random number right there

This topic is closed to new replies.

Advertisement