Jump to content
  • Advertisement
Sign in to follow this  
Tano_ITA

[c++] Basic Collision Detection

This topic is 3245 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

Hello, i've a new question about my game =). This time i will ask you something about collision detection. My game system is just like a 2D Vertical Shoot em up, (but all is 3D), i'm using Ogre3D as Engine, when i press a key on my keyboard i shoot a Bullet on the screen. Now i want to detect the collision between my bullet and a object on the screen. I've read something about collsion detection, but is a really huge argument and i don't know where i can start. So my question is: how can i detect the collision betweek a bullet and a mesh on my screen? The gameplay is like a 2D game, i (think) i don't need a complex collision manager. I've thinked about a raycast for all bullets, but is really inefficient.. or not? Thanks for you reply and sorry for my english! =)

Share this post


Link to post
Share on other sites
Advertisement
If you're not too worried about exact hits, and your game is primarily 2D (even though, as you said, you're using OGRE to display 3D graphics) you could just use ray-square or ray-circle intersections. Using this, each potential target has an invisible circle or square, which we'll call the target's collision hull, and when you fire your weapon, assuming the bullet has no travel time, you cast a ray from the bullets origin, and test for intersection against each targets collision hull. I don't have the math here, but a quick search engine search for the above terms should find it for you.

Then you just need a way to reduce the number of targets you need to check if you have lots of them on screen at once..

EDIT: As an aside, if your bullets don't reach their targets immediately, just create a "bullet" object which also has a collision hull, and test for collisions between hulls each frame that the bullet is alive. It's usually a goood idea to kill these objects off after a while though, but I'm sure you already knew that.

Hope this was helpful, and good luck!

Share this post


Link to post
Share on other sites
for bullets you can use line-section-"casting" (this might not be the proper term) too. It's not much harder to implement then ray-casting, only the lines aren't infinite, but just a section of it. So if your bullet isn't traveling with infinite speed, you can use it: one end of the section is the current position of the bullet, the other is the old position of it (position in previous frame), this is a quite precise method.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!