+ 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?

20th Apr 2021, 1:13 PM
durian
durian - avatar
6 odpowiedzi
+ 3
for i from 0 to entities.len - 2 for j from i + 1 to entities len - 1
20th Apr 2021, 3:08 PM
Gordon
Gordon - avatar
+ 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
20th Apr 2021, 6:38 PM
Dennis
Dennis - avatar
0
Mirielle i see..prob i should take account the area too..thanks :)
20th Apr 2021, 7:16 PM
durian
durian - avatar
0
Dennis Thanks..i will look into that:)
20th Apr 2021, 7:17 PM
durian
durian - avatar
0
@gordon nice.. i should do like this.. thanks :)
20th Apr 2021, 7:19 PM
durian
durian - avatar