Map-clipping with OBJs?

Hi, seems like I really enjoy using Three.js. So today I created a project, where you can move and look around, however I have created an arena as an OBJ, which I want the user not to be able to pass though. So, if I dont want to limit the user on my own, how can I add clips to my arena so they wont pass through?

You can calculate whether or not the object / player is navigating over the map by raycasting from the player position downwards (calculate intersections only with the ground mesh.) If there’s no collision, it means that the player has left the map.

If you want to restrain player movement to only specific parts of the map, you can also create a separate (hidden) mesh that’ll serve as a navigation map (ie. a navmap):

This simplifies collision detection quite a lot, since you can only care about the intersections between navmap and the player - and adjust player position accordingly.

If you want to use the navigation mesh approach, you can have a look at Yuka which has a nav mesh implementation and many other features intended for game AI development.

There is also an example that demonstrate the map restriction feature.

1 Like

Sorry for replying so late. So, if I get it correctly, this method requires me to manually create an object, tak will be everywhere (relative to the default obj (or map)) where I dont want the player to go. If so, is there a method, that Id just make another copy of the map and make it somehow solid, literally, it being the object, which limits the player, however, not in height (y), because that would be buggy, since I want to also have some different height levels etc

to manually create an object

I think it can be generated automatically as well, using convex polygons. Whether the result would be useful depends on the algorithm (math can calculate slopes, but does not really understand context of specific surfaces, if they’re supposed to be walkable or not.)

however, not in height (y), because that would be buggy

What do you mean? As long as you keep celling at some minimum offset, and adjust raycaster to proper .near and .far values - it should work fine.

is there a method, that Id just make another copy of the map and make it somehow solid

Well, there’s nothing stopping you from using the map mesh as a navmesh - even without copying it.

If you’d like only parts of the map to be walkable:

Blender 👉 Open map file 👉 Edit Mode (tab) 👉 Right-click walkable / non-walkable parts (ctrl + C) 👉 X 👉 Delete Faces 👉 Enter

Screenshot 2020-12-09 at 04.25.41

Maybe this example will clarify it a bit (mind, if your map is complex, or you’d like many AI actors to navigate it - it’s better to use Yuka, since it also supports spatial indexing.)