VR city obj => auto collision? sanity check

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 :slight_smile: . 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 :slight_smile: )

omg, this is very exciting, I can’t wait to play with this

yes lol everyone is going to have to put up with my cyber-totalitarian aesthetic; it is the price of me organizing this haha

1 Like

Here is a couple of PG city model examples: https://playground.babylonjs.com/#4HUQQ#1481 and

1 Like

I’m going to take this one and add it to the vr starter kit; how can I quote you inside the sketch in the comments?

also currently working here to adapt it to the xr camera Glitch :・゚✧

        //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() {
          xr.baseExperience.camera.checkCollisions = true;
          xr.baseExperience.camera.ellipsoid = new BABYLON.Vector3(1, 2, 1);
          xr.baseExperience.camera.ellipsoidOffset = xr.baseExperience.camera.ellipsoid;

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?

@RaananW will be back tomorrow so I bet he ll be right on time :slight_smile:

1 Like

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.

I am trying to implement my own smooth locomotion; so, this seems like the first step.

I just found a really cool custom build of the mozilla vr emulator that has all the buttons and axes etc. (so I don’t have to set up debugging).

Once I get this working, I will move on to thinking about collisions in VR.

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 .

yep, check the code :slight_smile: those are private functions

1 Like

I’m going to try and see if I can do this myself ( :grin:) 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.

This will be addressed soon. Will keep you updated.

1 Like

returning to aking about VR collision (asked in the messages, but those are not public)

sort of re-realizing how powerful it is…

here’s townscraper in VR, can’t wait to walk on those towers and high levels: https://twitter.com/delta_ark/status/1432210242251546624

This is already commited :slight_smile:

This is the PR - add support for XR Movement Controller by brianzinn · Pull Request #10410 · BabylonJS/Babylon.js (github.com)

and this is the doc page:

1 Like