+ 1
collision detection
hi guys.. i want to check collision for entity with other entities in a scene im wondering if its okay to implement collision detection like this example, somewhere in update loop (pseudo code) for i from 0 to entities.len for j from 0 to entities.len if entities[i] != entities[j] , checkcollision(entities[i], entities[j]) this is O(n^2) right?is there a better way to check collision for every entity?
5 Answers
+ 3
for i from 0 to entities.len - 2
for j from i + 1 to entities len - 1
+ 3
With collision detection you want to avoid doing a collision test at all on entities that are far away.
Take a look at Quadtrees for 2D games or Octrees for 3D games.
https://en.wikipedia.org/wiki/Quadtree
https://en.wikipedia.org/wiki/Octree
0
Mirielle i see..prob i should take account the area too..thanks :)
0
Dennis Thanks..i will look into that:)
0
@gordon
nice.. i should do like this.. thanks :)