Jump to content

Continuous Gravity/ collision check


Recommended Posts


I'm playing around with the VR camera. So I made it to always move forward in the direction that you're looking at with the registerBeforeRender function.

But it seems that the camera doesn't check for gravity and collision unless I press one of the keyboard keys to move the camera. Is there a way to check for collision and add gravity all the time?

While I'm at it.. another question. I noticed that the VR camera doesn't display correctly in my cardboard. Both camera views are way to far apart to make a single 3D image. Are there settings where I could change that?

thanks :-)

Link to comment
Share on other sites

Hiya Flomo! 

We have seen this "kick the camera" thing before... it's annoying and lovable all at the same time.

Consider building a camera kicker.  scene.executeWhenReady(function(){camera.position.z += .0001});  MAYBE that will make the camera come alive (fall to ground) at scene startup.  Maybe not.  :)

Subject #2:  Here is a strange playground with a webVRFreeCam.  http://www.babylonjs-playground.com/#1JSXHW#16

This shows how to get a ref to a 'metrics' object. It has lots of cool knobs to turn.  In the above demo, we needed to widen the nose-bridge gap for someone.  (Notice how wide it is.)  

I think you need to change line 11 to true, to activate junk.

Goof around with all that, see if something is successful.  Let us know.  (thx)


Link to comment
Share on other sites

Thanks for your reply!

The camera metrics settings are just what I need. Just have to find the right settings now.

The camera kicker is not working unfortunately. I've made a playground to illustrate:


The camera should walk onto the ramp. But it goes right through. Only when pressing an arrow left/right it works as it should.

I guess I'm looking for this function: moveWithCollissions();

But that only works on meshes. Not on a camera.

Any ideas?



Link to comment
Share on other sites

Hi again.  Yeah, the kicker isn't working.  Sorry about that.  I gave that very same advice here, and it failed then, too.  Dummy me.

I have been doing some testing... http://www.babylonjs-playground.com/#1GL6RR#2

(I like to test this with camera-falls.  If the camera falls to the ground at scene start-up, then we know we have won this challenge.)  :)

With low gravity like my testing scene, it takes THREE cursor-up or cursor-down... to make the camera hit the ground.  Terrible.

This POSSIBLY indicates... that gravity movement on the camera is ONLY active while the camera still has inertia.  When camera inertia ends, gravity-checking/update ends, too.

But nothing is for sure.  :) 

The fun is in the learning!  SO, now we can continue down the trail... to learn how the engine/scene "services" camera collisions and gravity.  It looks like a fun, nicely wooded learning trail, and I bet we will find a secret pine cone that allows us to beat this challenge.

Update:  http://www.babylonjs-playground.com/#1GL6RR#4  -  Line 41 - camera._needMoveForGravity = true;   Cooool!  Magic pine cone!

Auto-fall is working, but this... http://www.babylonjs-playground.com/#1GL6RR#5 ...still shows camera goes THROUGH the ramp.  hmm.

Link to comment
Share on other sites

Hi Wingnut,

you're being a real wingman here! And indeed you're getting close.

But if the angle is too steep or camera speed too high, the collision will be missed. Something that moveWithCollissions() was created for. ( This function will try to move the mesh according to given velocity and will check if there is no collision between current mesh and all meshes with checkCollisions activated.)

Or should the camera be moved in a different way? Would it be possible to emulate a key-press of the forward button?

Or should I give up and make the camera a child of a mesh? That's what I did in this PG: http://www.babylonjs-playground.com/#1GL6RR#6

It works perfectly. But feels like it shouldn't be like this :-)


Link to comment
Share on other sites

After implementing that solution in my scene it seems like it's working (on pc browsers)

But when using my iPhone, the camera switches moving forward and backward depending on the angle of looking up/down.

See here: http://flomotion.nl/temp

And also.. after changing metrics the file crashes immediately on iPhone (does work on pc).

So.. looks like the VR cam needs some more attention.

Link to comment
Share on other sites

Nice scene, Flomo!  I don't think I can help much more.  Camera moving, or moving mesh with camera parented to it... both are good ideas.  Sorry to hear about the iPhone troubles.  I will keep thinking, though.  Please tell us of your discoveries... if some are made.

Link to comment
Share on other sites

Thanks Wingnut,

I did manage to fix the camera moving backward. Not a handsome fix but a working one. If the camera looks up it flips all angles (only on phone, not on PC). But everything looks smooth. Except for the forwards speed vector.  That seems to be reversed.

var moveCamera = function() {
    var camSpeed = 0.06;
    var gravity = -0.15;
    if (Math.abs(camera.rotation.x)>2 && Math.abs(camera.rotation.z)>2) {
        camSpeed = camSpeed*-1;
        camera.rotation.z = Math.abs(camera.rotation.z*-1);
    var forwards = new BABYLON.Vector3(parseFloat(Math.sin(camera.rotation.y)) * camSpeed, gravity, parseFloat(Math.cos(camera.rotation.y)) * camSpeed); 
    camera.position = camMesh.position.clone().add(new BABYLON.Vector3(0, 2.8, 0));


@Deltakosh: The Temechon VR cam does work on my iPhone. So I'll try to figure out what I'm doing wrong. Thanks

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...