Jump to content
  • Advertisement
Sign in to follow this  
savail

How to store information about different objects in collisions?

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

Hey,
So I have in my game 3 different classes which store information about: player and bots characters; skill effects; obstacles (like a stone for example). I need to handle collision between all of these objects and wonder how to do it as efficiently as possible. So, the first class that stores info about players and bots lets me do the collision between them easily but then I need to handle also collision between skill and skill, between skill and bot/player, between obstacle and player/bot etc etc. I know I could create only one class for all those objects and then it would be simple but it would be a little mess in the class becouse all objects would have all variables even those which are not needed. I could also do separate collision checking loops for all cases as I mentioned above but it would take so much space in code and wouldn't be easy in modyfing I guess.
Therefore I would be very grateful for any advice on: Topic title.

Share this post


Link to post
Share on other sites
Advertisement
Is this 2d or 3d? What kind of shapes are you using for the collisions?

One simple and fairly extensible way is to have a class "CollisionComponent" or "PhysicsComponent", which stores just the information needed to test for collisions, as well as the object that owns it. Keep all of the components in a list, and perform a collision check, for each two that collide notify their owners.

Share this post


Link to post
Share on other sites
Thanks a lot for reply, it's pretty good idea. Btw, sorry I forgot to mention that it's 2d game and I'm using sprites.

Share this post


Link to post
Share on other sites
As turch mentioned, you could associate a physics component with the object, and just check all the physics objects against each other. As long as these objects know it owner, when a collision occurs, you can reference the 2 objects that collided.

The standard way is to have the objects that can collide in a collidiable list; when an object moves you check it against other objects in that list.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!