So, I made this VR city example and am going to post it to all the xr discords or whatever. It’s on glitch, so you can remix it with the click of a button.
I have a kind of beginner question, which is: is there an auto-obj collision device? Meaning, let’s say you upload a complex obj, is there some kind of collision object that can automatically take care of it? like I upload all these buildings and it auto-makes a collider of some kind?
When you say collision detection, what kind do you mean?
Babylon has a collision system for meshes and input-oriented cameras (keyboard, mouse). But knowing you, I know you probably already know that . What exactly is your usecase?
So, I uploaded this mega huge obj file of this pretty complex city. I’ve never used the collision system before (I’m looking through the docs now), but is there a way to just say “the player can’t go through every wall,” like babylonjs just makes the entire obj a collider? Does this make sense?
I’m seeing stuff like this Mesh Intersections | Babylon.js Documentation which is very much “by hand” like you have to draw up your own mesh colliders… a cube there, an ellipsoid there, rather than a just: don’t pass through this complex object.
if you enable collision on the object you loaded, your camera will nit gi through it, if you use a cllision-enabled camera. If you want mesh-to-mesh collision you can move the mesh using moveWithCollision and then make sure the mesh doesnt go through walls
For the simple camera collisions you don’t need physics, just built-in collision function.
Small example - https://playground.babylonjs.com/#5UJIE1#2
(in my opinion, the model could be nicer and smaller but with colors, currently it may frighten some beginners )
//////////COLLISIONS!
//https://playground.babylonjs.com/#5UJIE1#2 adapted from this playground
//here we are doing some thinking about collisions
scene.collisionEnabled = true;
//this checks if we're in VR, then runs out enable collisions function
function enableVRCollisions() {
//console.log("hi");
xr.baseExperience.camera.checkCollisions = true;
xr.baseExperience.camera.ellipsoid = new BABYLON.Vector3(1, 2, 1);
xr.baseExperience.camera.ellipsoidOffset = xr.baseExperience.camera.ellipsoid;
}
xr.baseExperience.sessionManager.onXRSessionInit.add(
enableVRCollisions
);
///////////
I seem to be teleporting through objects; I’m wondering if I need to create a smooth locomotion function to test if collision is really working. Is there a pre-packaged smooth locomotion option, or should I write it myself? Am I reasoning correctly here (or should you not actually be able to teleport through buildings)?
just a gentle nudge on the above (bc the hack night is tomorrow), if you don’t have time no worries, but wondering if I have to enable smooth locomotion (and if there is already code for that or if I have to write it myself) in order to get collisions in VR?
The XR camera doesn’t check for collisions ATM, as (“officially”) you can’t move the camera constantly like you move a free camera. The XRCamera supports teleportation for movements, which only allows you to land on predefined meshes, which will allow a different type of “collision detection”.
If you implement your own movement, you can check for collisions using the collision system on each frame and update the camera’s position accordingly. Check the FreeCamera (mainly the function _updatePosition and collideWithWorld). There is already an issue to allow free movement using XR controllers, this is a part of this ticket.
OK, I implemented my own sliding movements. When you say “check the freeCamera,” you mean go inside of babylon and check the free camera, right? bc in the documentation FreeCamera | Babylon.js Documentation I don’t see _updatePosition or collideWithWorld .
I’m going to try and see if I can do this myself ( ) but I’m beginning to think VR collision is more and more important.
There are two immediate use cases:
(1.) Walking/sliding around the VR city, I don’t want to go through buildings.
(2.) I think that generating terrain and then being able to walk on that terrain is pretty important.
I mean this is metaverse-ish stuff; I think we should have it. It will help for creating actual virtual worlds that multiplayers can/want to explore.