0
\$\begingroup\$

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?

\$\endgroup\$

2 Answers 2

1
\$\begingroup\$

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.

\$\endgroup\$
0
\$\begingroup\$

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.

http://en.wikipedia.org/wiki/Bounding_volume#Common_types_of_bounding_volume

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .