freetoplay Posted May 12, 2018 Share Posted May 12, 2018 How can I get the camera to "center" (not sure if center is the right word here) directly on the model like the Babylon Sandbox does when you drop in the file? Any help would be greatly appreciated. Quote Link to comment Share on other sites More sharing options...
MarianG Posted May 12, 2018 Share Posted May 12, 2018 Hi. Try this: camera.setTarget(mesh); Wingnut 1 Quote Link to comment Share on other sites More sharing options...
freetoplay Posted May 12, 2018 Author Share Posted May 12, 2018 Doesn't seem to work for me. This is what my code looks like: var createScene = function () { // create a basic BJS Scene object var scene = new BABYLON.Scene(engine); // loader var loader = new BABYLON.AssetsManager(scene); // light var light0 = new BABYLON.HemisphericLight("Hemi0", new BABYLON.Vector3(0, 0, 0), scene); light0.specular = new BABYLON.Color3(0, 0, 0); // cam // Parameters : name, position, scene var camera = new BABYLON.UniversalCamera("UniversalCamera", new BABYLON.Vector3(0, 0, 10), scene); // Targets the camera to a particular position. In this case the scene origin camera.setTarget(BABYLON.Vector3.Zero()); // Attach the camera to the canvas camera.attachControl(canvas, true); var model = loader.addMeshTask("box", "", "./", "character.glb"); loader.onFinish = function(task) { camera.setTarget(task[0].loadedMeshes[0].position); engine.runRenderLoop(function () { scene.render(); }); }; loader.load(); return scene; }; Quote Link to comment Share on other sites More sharing options...
MadeByJawns Posted May 13, 2018 Share Posted May 13, 2018 Recreated your code as a playground and it seems to work fine? https://www.babylonjs-playground.com/#ZJYNY#71 However, before I "saved" it onto the playground, I noticed that using your code camera.setTarget(task[0].loadedMeshes[0].position); instead camera.setTarget(model.loadedMeshes[0].position); caused console errors in the inspector, so first, try that and see if it still doesn't work. If it doesn't work, then try deleting the first camera.setTarget so we can determine that it's not because of the fact that the asset manager is asynchronous so because your scene setup is quite simple, it could be loading it very quick and changing the camera target, then being overwrite by your first camera.setTarget GameMonetize and Wingnut 2 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.