My code below,
I like how the cube moves so far, but I really want the pitch up/down to move that (x) axis rotation and the roll movement to move the z-axis rotation but still follow the cube if you get my drift. Ultimately im trying to get flight sim controls with the mouse. As it is these 2 axis seem to be locked and wont move. Im a beginner here so id appreciate some help understanding if im on the right track with camera choice and so forth.
Cheers.
window.addEventListener(‘DOMContentLoaded’, function(){
var canvas = document.getElementById('canvas');
var engine = new BABYLON.Engine(canvas, true);
var createScene = function(){
var scene = new BABYLON.Scene(engine);
scene.clearColor = new BABYLON.Color3.White();
var ground = BABYLON.Mesh.CreateGround('ground1', 200, 200, 10, scene);
ground.position.y = -10;
var box = BABYLON.Mesh.CreateBox("Box",3,scene);
box.position.y = -1;
var box2 = BABYLON.Mesh.CreateBox("Box2",3.0,scene);
box2.position.y = -5;
// var camera = new BABYLON.ArcRotateCamera("arcCam",
// BABYLON.Tools.ToRadians(45),
//BABYLON.Tools.ToRadians(45),
//10.0,box.position,scene);
//camera.attachControl(canvas,true);
// Parameters: name, position, scene
var camera = new BABYLON.FollowCamera("followCam",BABYLON.Vector3.Zero(),scene);
camera.lockedTarget = box;
camera.radius = 20;
camera.heightOffset = 2;
camera.attachControl(canvas,true);
camera.inputs.clear();
function onMouseMove(){
var UpDown = -(scene.pointerY-canvas.height/2)/800;
var Roll = (scene.pointerX-canvas.width/2)/600;
box.rotation.x = UpDown; //up - down
box.rotation.z = Roll; //bank left - right
}
canvas.addEventListener(‘mousemove’,onMouseMove);
setInterval(function(){
//var speedx = Math.cos(ground.rotation.y)/10; //x pos
//var speedz = Math.cos(ground.rotation.x)/10; //z pos
var rotateY = (scene.pointerX-canvas.width/2)/10000;
box.rotation.y += rotateY;
//box.position.z -= speedz;
//box.position.x += speedx;
}, 10);
var light = new BABYLON.PointLight("pointLight", new BABYLON.Vector3(0,10,0),scene);
light.parent = camera;
light.diffuse = new BABYLON.Color3(1,1,1);
var material = new BABYLON.StandardMaterial("material1",scene);
material.diffuseColor = BABYLON.Color3.Blue();
// material.emissiveColor = BABYLON.Color3.Red();
// material.specularColor = BABYLON.Color3.Red();
//material.diffuseTexture = new BABYLON.Texture("account.png",scene);
box.material = material;
return scene;
}
var scene = createScene();
engine.runRenderLoop(function(){
//scene.getMeshByName("Box").position.z -= .1;
scene.render();
});
});