Advertisement

Bullet Collision

Started by September 21, 2016 02:54 PM
0 comments, last by _paf 8 years, 2 months ago

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?

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.

This topic is closed to new replies.

Advertisement