Jump to content
  • Advertisement
Sign in to follow this  
null;

Bullet Collision

This topic is 732 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 started to work on a little game recently.

 

Essentially, it involves throwing a block, and the player teleports wherever it lands.

 

I have an ObjectId enum which stores my objects for the game. So far, I have a Block, Player, and Bullet (which is the thing you throw in the game) enum. Every new block/bullet that's created is passed its respective enum in its parameter. I use this tag to reference the objects.

 

Anyways, the way I'm currently checking to see if the 'bullet' landed on ground, is by literally iterating over every block there is in the game, and checking if the 'bullet' intersected with them. Obviously, this isn't very efficient, and throwing multiple at the same time causes quite a bit of lag.

 

Is there a better way to do this? 

Share this post


Link to post
Share on other sites
Advertisement
Essentially, it involves throwing a block, and the player teleports wherever it lands.   I have an ObjectId enum which stores my objects for the game. So far, I have a Block, Player, and Bullet (which is the thing you throw in the game) enum. Every new block/bullet that's created is passed its respective enum in its parameter. I use this tag to reference the objects.

 

Sorry but I'm a bit confused. Do you throw a bullet or a block?

Or do you mean you throw a bullet, that lands on a block, and then the player teleports to that block?

 

Either way, you need to reduce the number of objects you test for collision.

 

Physics/Collision libs usually have two phases for testing collisions: the broad phase and the narrow phase.

 

The broad phase is responsible for finding object pairs that are potentially colliding, and discarding the ones that are not.

This phase usually uses some form of spatial subdivision for the world (quadtrees, octrees, etc) and also tests for potential collisions between objects by using simple bounding volumes (like AABBs or OBBs) instead of the actual object's collision model (which can be much more expensive to test).

 

The narrow phase is where you check if two objects are actually colliding, using their actual bounding volumes (like you are doing in your code).

 

Summing it up, the broad phase very quickly and roughly discards non colliding object pairs, and the narrow phase performs the actual test to see if two objects are colliding.

 

This is much better explained in this article, that I came across a while ago.

It is a 3 part article that also contains physics and constraints, so give it a read if you're interested.

 

Anyway, hope it helps.

Edited by __SKYe

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!