How can I detect collision more efficiently?

Hello!

I am making a game: bowdown.io

Right now for collision detection I am using several Raycasters that originate from the player’s position and I’m using them to detect collisions with the game map 3d object. However, the more complicated that I make the map, the more slow the game gets and I’m pretty sure this is due to the way I’m doing collision detection because when I disable collision detection the game runs smooth as butter.

Does anyone have any good efficient ways to detect collisions with a large complicated game map?

Thank you

1 Like

Here https://discourse.threejs.org/t/garden-from-the-shining/10104 in model I use additional poligons to check is player object in poligon or not.

Nice animation! ))

1 Like

I just played your demo today and I was really impressed by how smoothly it runs!
Your suggestion works will for your game design with the maze and all but I’m not sure how I could do this with a more dynamic environment

I suggest using a spatial index.

A shameless plug, but my game engine does come with a spatial index by default.

There are a ton of different spatial indices, but the main goal is to move from having to check every polygon in the scene, to having do log(n) of that. So if you have 100,000 polygons in your scene, naive method (three.js standard raycaster) will result in 100,000 checks, with an optimal BVH (a kind of spatial index) you will need log(100000) checks, that is - 5. Needless to say, the more polygons you have - the more bang you get for your proverbial buck.

PS:
Love your game, looks awesome and plays quite smoothly.

4 Likes

Thanks for the advice Usnul and thank you for the compliment! It means a lot!

1 Like