Can anyone tell me how can I not allow the movement through "cave" walls?

I only want the movement through a door in the cave. But not through the walls.
I’m not sure on how to approach this problem.

Model: Cave - Download Free 3D model by Valsev [43b086d] - Sketchfab

As an option, try this plugin for fast raycasting:

1 Like

Thanks @prisoner849.

But I wanted to know that is raycasting the only option?

Can’t we make the player and the geometry of this cave a cannon.js static body, such that it automatically does not allows the movement through?

Can’t we make the player and the geometry of this cave a cannon.js static body, such that it automatically does not allows the movement through?

Of course a physics engine is an answer - if that’s what you want then you should use cannon or another one of the several physics libraries out there.

Three-mesh-bvh provides more than just raycasting, though. If you want a more custom, controllable solution for limiting movement based on geometry you can use the bvh for spatial queries. These two examples show how to use spatial queries for this purpose.

https://gkjohnson.github.io/three-mesh-bvh/example/bundle/characterMovement.html

https://gkjohnson.github.io/three-mesh-bvh/example/bundle/physics.html

1 Like

Thanks @gkjohnson.
How can we approach this via physics engine?

I tried to create a convexPolyhedron sorts shape for the walls of cave, but it gives the error saying faceNormals looks like it points into the shape? The vertices follow. Make sure they are ordered CCW around the normal, using the right hand rule.

Is there any method to convert any custom geometry to a cannon body?

I am not an expert in using these physics engines but it sounds like you’re geometry normals need to be made consistent with the geometry faces.

Thanks a lot @gkjohnson, three-mesh-bvh is working perfectly!!
Just quite a bit learning curve of those examples.
I’d love to know if there are any more simpler tutorials/examples of this.

@kreysix if you really want to try the physics simulation approach, please consider that non-movable rigid bodys have to be really simple geometries (i.e. convex hull proxies or simplifications like AABBs).

In your door case: portals are generally made up of basic simple cubes, one for each side of the hole. If you are generating meshes for working with cannon.js you shoud give a try to three-to-cannon for converting to cannon geos.

Now, if you plan to include ramps, different floors, and more complex layouts, you could try another approach, wich consists in modeling a ‘navigation mesh’ in a dcc software (like blender) and importing this for defining walkable areas in your app. If that is the case, you can get to three-pathfinding, which includes all that is required to get you up and running.

@Antonio great, thanks for this insight!

Although, three-path-finding gives us way to click and go to a certain defined point.

Is it possible to create a free roam sort of path, that too the movement should be with the keyboard keys. Like third person.