Jump to content



Recommended Posts

Hello I am new in this, I am working on a project for the college.

I am trying to make an elevator when i am inside the elevator and the elevator floor goes up it wont detect the camera to push the camera up.

my collissions are enabled and is working fine i can detect obstacles when I move the camera(Freecamera) with the keyboard.

and i can step up on the floor of the elevator.

but when I Have a moving object and it hits the camera it doesnt detect the obstacle. (elevator floor in my case).

the link of my code is below.

I am sorry the code is terribly arranged.

the script: https://drive.google.com/open?id=1BSs2BB0Ns9BDmwLSyePiqHtKEBHM9F91

The whole project: https://drive.google.com/open?id=1xm0JyQXJY2yD-wck9Y3bs5tKcg01LYRI


Thanks a lot :)


scene.collisionsEnabled = true;
camera.checkCollisions = true;
camera.applyGravity = true;
camera.collisionRadius = new BABYLON.Vector3(2, 2, 2);
camera.ellipsoid = new BABYLON.Vector3(1, 4.5, 1);

var elevupfun = function (mesh2,mesh4,mesh5,mesh6) {
var posopdor1 = new BABYLON.InterpolateValueAction(BABYLON.ActionManager.OnPickTrigger, mesh4, "position",new BABYLON.Vector3(11.625,  7.625, 35.5), 200);
var scalopdor1 = new BABYLON.InterpolateValueAction(BABYLON.ActionManager.OnPickTrigger, mesh4, "scaling", new BABYLON.Vector3(0, 1, 1 ), 200);
var posclosdor1 = new BABYLON.InterpolateValueAction(BABYLON.ActionManager.OnPickTrigger, mesh4, "position",new BABYLON.Vector3(13.5,  7.625, 35.5), 200);
var scalclosdor1 = new BABYLON.InterpolateValueAction(BABYLON.ActionManager.OnPickTrigger, mesh4, "scaling", new BABYLON.Vector3(1, 1, 1 ), 200);
var posopdor2 = new BABYLON.InterpolateValueAction(BABYLON.ActionManager.OnPickTrigger, mesh5, "position",new BABYLON.Vector3(19.125,  7.625, 35.5), 200);
var scalopdor2 = new BABYLON.InterpolateValueAction(BABYLON.ActionManager.OnPickTrigger, mesh5, "scaling", new BABYLON.Vector3(0, 1, 1 ), 200);
var posclosdor2 = new BABYLON.InterpolateValueAction(BABYLON.ActionManager.OnPickTrigger, mesh5, "position",new BABYLON.Vector3(17.25,  7.625, 35.5), 200);
var scalclosdor2 = new BABYLON.InterpolateValueAction(BABYLON.ActionManager.OnPickTrigger, mesh5, "scaling", new BABYLON.Vector3(1, 1, 1 ), 200);
var elevup = new BABYLON.InterpolateValueAction(BABYLON.ActionManager.OnPickTrigger, mesh6, "position",new BABYLON.Vector3(15.25,  30.1, 40.0625), 4000);
elevupfun(elevinsidebutton,elevatordoor1L,elevatordoor1R, elevground);


Link to comment
Share on other sites

Hiya Zareh, welcome to the forum!

You are a lucky person.  We have a fun function:   elevatorFloor.moveWithCollisions(new BABYLON.Vector3(someAmount, someAmount, someAmount));


Here in our BJS playground, I have assembled a demo.  We like the playground.  When forum users can create a playground to illustrate the problem, a very large team of helpers will work to find solutions and provide great ideas.

In the above playground, line 15 is interesting.  The ._needMoveForGravity is what causes the FreeCamera to start falling... when scene.isReady (with the help of camera.applyGravity, of course).

The MOST interesting part... is the plane.moveWithCollisions() in line 55.  (plane == ground)

I don't know how much JS experience you have.... but a setTimeout (in line 52) can be used as a delay.  The delay is about 10 seconds, dictated by the '10000' in line 61;

So, the camera starts falling immediately, and after 10 seconds... I do a 'registerBeforeRender(some function)'.  I insert some code... into the scene render-loop... to be executed every rendering (but only if elevator floor-plane is LESS THAN 40 units into the air).  With me?  I hope so.

If we raise the elevator floor using .moveWithCollisions... the camera will raise WITH the floor-plane.  You can see it happen in that demo. 

But... we are using .moveWithCollisions... which has the 'behavior' of disallowing movement IF a (non-scrub-around-able*) collision happens.  That is why the elevator raising... stops when it hits the bottom of the collision-active box that is sitting in the air.

* Continued .moveWithCollisions AFTER two mesh ellipsoids collide... can cause moved mesh to "scrub-off-of" collided mesh.  This includes dive-under, climb-over, and scrub-off to either side.  Pretend you are pushing two bowling balls together.  If not perfectly aligned, the balls will somehow move-around each other.  The AMOUNT of offset-from-perfectly-aligned... necessary to cause two pushing collided-mesh.ellipsoids to "scrub-off"... is set via the float value of engine.collisionsEpsilon.

I will stop there, and see how well you understand.  I am not the best at explaining things.  I hope I was somewhat clear and didn't accidentally say something incorrect.  :)

Feel free to make edits to that playground, and do more RUNS, and make more SAVES, and paste the URL's for newly-saved playgrounds... here... to this thread... if you wish to talk about something. 

You can't hurt ANYTHING in the playground (unless you bang your head with a hammer while using it).  :)  There is no chance to accidentally damage ANY already-saved or built-in playground demos.  The BabylonJS playground is a great app... we all LOVE it.

(we're a little concerned about a screen-scroll that causes a white line across the bottom of the app... but that's for playground admin to deal-with.)  :)

I hope this helps.  Stay in touch.

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...