BabylonJS - Camera is parent of model
The camera moves so the model. It gives the impression that the blue box moves but it's the red box which moves with the camera.
HTML
<script src="https://rawgit.com/BabylonJS/Babylon.js/master/babylon.1.13.js"></script>
<canvas id="renderCanvas"></canvas>
CSS
#renderCanvas {
width: 100%;
height: 100%;
min-height: 100%;
}
JavaScript
if (BABYLON.Engine.isSupported()) {
var canvas = document.getElementById("renderCanvas");
var engine = new BABYLON.Engine(canvas, true);
var scene = new BABYLON.Scene(engine);
var light0 = new BABYLON.PointLight("Omni0", new BABYLON.Vector3(0, 100, 100), scene);
var camera = new BABYLON.FreeCamera("Camera", new BABYLON.Vector3(0, 0, -10), scene);
var cube = BABYLON.Mesh.CreateBox("Box", 2, scene);
cube.position.x = 3;
var model = BABYLON.Mesh.CreateBox("Model", 2, scene);
model.position.z = 13;
model.rotation.z = 1;
model.rotation.y = 1;
model.parent = camera;
scene.beforeRender = function() {
camera.position.x = Math.cos(new Date() / 1000);
};
// Material
var material = new BABYLON.StandardMaterial("default", scene);
material.emissiveColor = new BABYLON.Color3(0.3, 0.3, 0.5);
cube.material = material;
var material = new BABYLON.StandardMaterial("default", scene);
material.emissiveColor = new BABYLON.Color3(1.0, 0.0, 0.0);
model.material = material;
// Render loop
var renderLoop = function () {
scene.render();
};
// Launch render loop
engine.runRenderLoop(renderLoop);
}