gryff Posted February 27, 2014 Share Posted February 27, 2014 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 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted February 27, 2014 Share Posted February 27, 2014 You can create an invisible plane well oriented on top of your staircase (we did that for Espilit demo) Quote Link to comment Share on other sites More sharing options...
gryff Posted February 28, 2014 Author Share Posted February 28, 2014 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 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted February 28, 2014 Share Posted February 28, 2014 Beware to use checkCollisions and not physics when it is related to camera collisions:) Quote Link to comment Share on other sites More sharing options...
gryff Posted March 19, 2014 Author Share Posted March 19, 2014 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 GameMonetize and Xanmia 2 Quote Link to comment Share on other sites More sharing options...
Xanmia Posted March 20, 2014 Share Posted March 20, 2014 Wonder if you could do a bob of the camera on accent/decent of that stair plane, simulating a stair affect... Just a thought, would be cool but probably a bit of work to get it correct. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.