So, I'm having trouble with babylon.js. I'm trying to make a simple example where I have box colliders on my player object and the ground with physics applied for gravity and collision. I've run out of ideas as to what I could be doing wrong. Please help! I'll provide the playground link since people don't think we use it, along with the raw code.
link: http://www.babylonjs-playground.com/#1PK6ED#1
Raw Code:
window.addEventListener('DOMContentLoaded', function(){
var canvas = document.getElementById('canvas');
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
var engine = new BABYLON.Engine(canvas, true);
var createScene = function(){
//var gravity = parseFloat(0.1);
var scene = new BABYLON.Scene(engine);
var camera = new BABYLON.ArcRotateCamera("ArcRotateCamera", 1, 0.8, 10, new BABYLON.Vector3(0, 0, 0), scene);
camera.attachControl(canvas, false);
var light = new BABYLON.HemisphericLight('light1', new BABYLON.Vector3(0,1,0), scene);
scene.enablePhysics(new BABYLON.Vector3(0, -10, 0), new BABYLON.OimoJSPlugin());
scene.collisionsEnabled = true;
var player = BABYLON.Mesh.CreateBox("player",2,scene);
player.position = new BABYLON.Vector3(0,20,0);
player.checkCollisions = true;
var wing = BABYLON.Mesh.CreateBox("wing",2,scene);
wing.position = new BABYLON.Vector3(0,0,0);
wing.scaling.x = 2;
wing.scaling.y = .3;
wing.checkCollisions = true;
wing.parent = player;
camera.parent = player;
var ground = BABYLON.Mesh.CreateGroundFromHeightMap("ground", "data/images/heightMap_jpg.jpg", 400, 400, 500, 0, 10, scene, false);
var meshesColliderList = [];
for (var i = 1; i < scene.meshes.length; i++) {
if (scene.meshes[i].checkCollisions && scene.meshes[i].isVisible) {
scene.meshes[i].setPhysicsState(BABYLON.PhysicsEngine.BoxImpostor, { mass: 0, friction: 0.5, restitution: 0.7 });
meshesColliderList.push(scene.meshes[i]);
}
}
console.log(meshesColliderList);
return scene;
}
var scene = createScene();
engine.runRenderLoop(function(){
scene.render();
});
window.addEventListener('resize', function(){
engine.resize();
});
});