Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm building a game using WebGL and Three.js, and so far I have a terrain with a guy walking on it. I simply cast a ray downwards to know the terrain height.

How can I do this for other 3D objects, like the inside of a house? Is this possible by casting many rays in every direction of the player?

If not, I would like to know how I can achieve the simplest collision detection possible for other meshes. Do you have to cast a ray to every triangle in every mesh nearby?

share|improve this question

Pick an open source 3D physics engine, and see how they do this. Better yet, use it and improve it if you need too, this would help the HTML5 community a lot.

share|improve this answer

You can use simpler, invisible objects like spheres and cubes to simulate the collisions. The person might have many many polygons, and he might be supposed to bounce off of a rock wall with many many polygons, but the person could be represented by a sphere and the rock wall as a simple plane, and have collisions detection work with those objects. There are many examples of code for colliding two spheres, two cubes (even easier if they're lined up with the axis) and many others.

If you need precise collision checking, you can start with the simple primitives and only if there's the chance of a collision between two objects do you try something more complicated.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.