Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Three.js is a graphics rendering library and does not concern collision detection. You need something different for that. Here's a few options:</p> <ul> <li>If your scene is mostly planar and rectangular, i.e. even though it's 3d, the player only walks on one 2d plane with walls having simple shapes, you could create a simple grid which marks the locations of obstacles and then you check your player's coordinates against the grid and cancel the movement if it ends up inside walls.</li> <li>Use a physics engine: <a href="http://chandlerprall.github.com/Physijs/" rel="nofollow">Physijs</a> is an easy-to-use and flexible Bullet dynamics engine wrapper for Three.js. You could wrap your scene mesh inside a single <code>Physijs.ConcaveMesh</code>, add a collision shape to your camera and have instant, accurate collision detection - but that's going to be slow if you have a decently complex scene.</li> <li>A better approach is to break your scene into discrete objects, such as rectangular wall sections and add cheap collision shapes (like cubes, spheres, cylinders) for them individually. Physijs could do that, and then there is <a href="http://schteppe.github.com/cannon.js/" rel="nofollow">cannon.js</a> (<a href="https://t.co/Ziol8oy8">see FPS demo here</a>).</li> <li>Roll your own collision detection. I don't really recommend this because it's a rabbit hole, but it will give you full control over what features, accuracy and performance trade-offs are perfect for you.</li> </ul> <p>Personally, I've created an FPS game with Three.js. My level design is very regular, so I could use the grid method for player collisions, but I also wanted dynamic objects (e.g. barrels, boxes etc.) and using Physijs allowed me to integrate them too almost trivially. The wall collisions are thus handled by creating Physijs cubes to wall sections.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload