Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

zaphod

Basic question

This topic is 6824 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m working on a game in c++. I want a collision detection method that looks like this:- detect_collision(player p, enemy e){ if(one of the enemy''s bullets overlaps with the player) kill the player; if(one of the player''s bullets overlaps with the enemy) kill the enemy; } If I write this method and call it from within the main game loop, for the player and each enemy, the collision detection dosen''t work, however, if I cut and paste the code into the main loop (where p and e are directly available) the program works fine. What''s going on? thanks in advance. felix.

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
You passed the parameters in a wrong way!

You should try this ( so just change the function header! ):

detect_collision( player &p,enemy &e ) // &p and &e are
{ // references!
....//your code
}

Your problem was ( is? I don''t hope so! ) that you created two new objects ( enemy and player )in each function call. So you just changed the state of this new objects and not the state of the two ones you passed to the function!

If you have more trouble, call me:

Centum@gmx.net

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!