Jump to content

Climbing a staircase?


gryff
 Share

Recommended Posts

Is there a way to move the FreeCamera up a staircase?

 

I've tried a trick I picked up in Second Life where the staircase itself has collision checks turned off and an invisible plane layed down in the same place and sloping from top to bottom of the staircase. This plane has check for collisions. It does not work - the bounding box for that plane in Blender is cube shape.

 

Does a plane directly created in Babylon.js also have that cube type of bounding box?

 

And is there a way to move a Free Camera up a staircase that the experts have come up with - perhaps playing with gravity settings in some way?

 

cheers, gryff :)

Link to comment
Share on other sites

You can create an invisible plane well oriented on top of your staircase (we did that for Espilit demo)

 

 

@Deltakosh: As I said above that is a trick I picked up in Second Life. And I've been trying to create a plane in Blender as part of a .babylon file. I can't get it to work - I've tried 3-4 times exporting from Blender but it seems to be creating a cube like bounding box..

 

I will keep trying.

 

cheers. gryff :)

Link to comment
Share on other sites

  • 3 weeks later...

OK after going through the tutorials on collisions (09-11) and a lot of hair tearing, I have final got a solution to stair climbing:

 

Climb Stairs

 

This is the relevant code:

//Load a basic scene    var scene = new BABYLON.Scene(engine);        var light0 = new BABYLON.PointLight("Omni", new BABYLON.Vector3(0, 10, 30), scene);            var camera = new BABYLON.FreeCamera("FreeCamera", new BABYLON.Vector3(0, 0, -10), scene);    //Ground    var ground = BABYLON.Mesh.CreatePlane("ground", 50.0, scene);    ground.material = new BABYLON.StandardMaterial("groundMat", scene);    ground.material.diffuseColor = new BABYLON.Color3(1, 0, 0);    ground.material.backFaceCulling = true;    ground.position = new BABYLON.Vector3(0, -2, 0);    ground.rotation = new BABYLON.Vector3(Math.PI / 2, 0, 0);    // Create upper floor    var upper = new BABYLON.Mesh.CreateBox("upper", 5.65, scene);    upper.material = new BABYLON.StandardMaterial("upperMat", scene);    upper.material.emissiveColor = new BABYLON.Color3 (0,1,0);    upper.position = new BABYLON.Vector3(0, -1, 8.5);    upper.scaling = new BABYLON.Vector3(4, 1, 2);            // Create left wall    var lwall = new BABYLON.Mesh.CreateBox("leftwall", 2, scene);    lwall.material = new BABYLON.StandardMaterial("lwallMat", scene);    lwall.material.diffuseColor = new BABYLON.Color3 (1,1,0);    lwall.position = new BABYLON.Vector3(-2, 0, 0);    lwall.scaling = new BABYLON.Vector3(.1, 2, 3);        // Create right wall    var rwall = new BABYLON.Mesh.CreateBox("rightwall", 2, scene);    rwall.material = new BABYLON.StandardMaterial("rwallMat", scene);    rwall.material.diffuseColor = new BABYLON.Color3 (1,1,0);    rwall.position = new BABYLON.Vector3(2, 0, 0);    rwall.scaling = new BABYLON.Vector3(.1, 2, 3);                //Simple scaled box for stairs rotated 45 degrees    var box = new BABYLON.Mesh.CreatePlane("box", 2, scene);    box.material = new BABYLON.StandardMaterial("Mat", scene);    box.material.diffuseColor = new BABYLON.Color3 (0,0,1);    box.position = new BABYLON.Vector3(0, -1, 0);    box.scaling = new BABYLON.Vector3(2, 4, .01);    box.rotation.x = Math.PI/4;        //COLLISIONS BY GRAVITY    //---------------------    //Set gravity to the scene -make sure the Y value is less than camera speed    scene.gravity = new BABYLON.Vector3(0, -0.1, 0);       // Enable Collisions    scene.collisionsEnabled = true;    //Set the ellipsoid around the camera (e.g. your player's size)    camera.ellipsoid = new BABYLON.Vector3(1, 1, 1);        //Then apply collisions and gravity to the active camera and set speed    camera.checkCollisions = true;    camera.applyGravity = true;    camera.speed = .3;        //Set which meshes are collidable    ground.checkCollisions = true;    upper.checkCollisions = true;    rwall.checkCollisions = true;    lwall.checkCollisions = true;    box.checkCollisions = true;    

In actual practice, a mesh for the staircase would be added to the scene with checkCollisions set to false and the black tilted box be made invisible and placed inside the staircase mesh. It also seems to work with just creating a tilted plane too.

 

The crunch settings are :

 

1. scene.gravity = new BABYLON.Vector3(0, -0.1, 0);

 

2. camera.speed = .3;

 

If the absolute value of gravity.y is greater than the camera speed - you cannot walk up as you are falling faster than your motion up the slope.

 

cheers, gryff :)

 

    
 

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.

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

Loading...
 Share

  • Recently Browsing   0 members

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