bombe93 Posted February 2, 2015 Share Posted February 2, 2015 Hi, I'm trying to use Babylon.js to make a fun fps. How I can get to make the camera a jump after press the space button? I am following this guide (http://pixelcodr.com/tutos/shooter/shooter.html). Quote Link to comment Share on other sites More sharing options...
Dad72 Posted February 2, 2015 Share Posted February 2, 2015 create an event keyup or keydown. and add 2, 3 in y position of your camera simply. For exemple:window.addEventListener("keyup", onKeyUp, false);function onKeyUp(event){ switch (event.keyCode) { case 32: your_camera.position.y += 3; break; }}Of course, your camera must be gravity and collisions with the ground not to stay in the air and pass through the ground. Quote Link to comment Share on other sites More sharing options...
Mimetis Posted February 3, 2015 Share Posted February 3, 2015 var cam = this.scene.cameras[0];cam.animations = []var a = new BABYLON.Animation( "a", "position.y", 20, BABYLON.Animation.ANIMATIONTYPE_FLOAT, BABYLON.Animation.ANIMATIONLOOPMODE_CYCLE);// Animation keysvar keys = [];keys.push({ frame: 0, value: cam.position.y });keys.push({ frame: 10, value: cam.position.y + 2 });keys.push({ frame: 20, value: cam.position.y });a.setKeys(keys);var easingFunction = new BABYLON.CircleEase();easingFunction.setEasingMode(BABYLON.EasingFunction.EASINGMODE_EASEINOUT);a.setEasingFunction(easingFunction);cam.animations.push(a);this.scene.beginAnimation(cam, 0, 20, false);You can try something like that too, it's a little bit more "smoothy" Quote Link to comment Share on other sites More sharing options...
bombe93 Posted February 3, 2015 Author Share Posted February 3, 2015 Thanks for the quick replies. I tried the suggestion of dad72 but does not work well, jumps but there is no gravity so remains high. I tried the suggestion of Mimetis but doesn't work, nothing happens. Have you other ideas? Hhas never happened to solve this problem? Quote Link to comment Share on other sites More sharing options...
Dad72 Posted February 3, 2015 Share Posted February 3, 2015 I tried the suggestion of dad72 but does not work well, jumps but there is no gravity so remains high. ==> Of course, your camera must be gravity and collisions with the ground not to stay in the air and pass through the ground. scene.gravity = new BABYLON.Vector3(0, -9.81, 0);camera.applyGravity = true;scene.collisionsEnabled = true;camera.checkCollisions = true;ground.checkCollisions = true; http://babylondoc.azurewebsites.net/page.php?p=22091 Quote Link to comment Share on other sites More sharing options...
iiceman Posted February 3, 2015 Share Posted February 3, 2015 Here is a playground with the ideas of dad72 and Mimetis combined. I changed the jump key to shift (space seems to trigger the playground to reload sometimes). http://www.babylonjs-playground.com/#XN87O#2 Is that what you wanted? Quote Link to comment Share on other sites More sharing options...
bombe93 Posted February 3, 2015 Author Share Posted February 3, 2015 Yes iiceman!I tried what you suggested but it returns an error. http://postimg.org/image/7044jbtdj/ Quote Link to comment Share on other sites More sharing options...
Dad72 Posted February 3, 2015 Share Posted February 3, 2015 You must use version 2.0 of babylon : CTRL for jump (spacebar seems update the playground) http://www.babylonjs-playground.com/#XN87O#5 Quote Link to comment Share on other sites More sharing options...
bombe93 Posted February 3, 2015 Author Share Posted February 3, 2015 i tried, when i do a left click mouse it freezes (With babylon 2.0 ). -------------------------The error with Babylon JS 2.0 is in this line, why? http://postimg.org/image/hp0ej094d/ Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted February 3, 2015 Share Posted February 3, 2015 GetDeltaTime is now on the engine: engine.getDeltaTime() Quote Link to comment Share on other sites More sharing options...
bombe93 Posted February 3, 2015 Author Share Posted February 3, 2015 I tried but it does not work.can you be more specific?however, the error that gives me is "Uncaught TypeError: undefined is not a function", does not seem to find something. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted February 3, 2015 Share Posted February 3, 2015 instead of using BABYLON.Tools.GetDeltaTime() please use engine.getDeltaTime() (with your engine object) Quote Link to comment Share on other sites More sharing options...
bombe93 Posted February 4, 2015 Author Share Posted February 4, 2015 Ok, where is engine object? I think engine object is in this file (Game.js). var VERSION = 1.0, AUTHOR = "[email protected]";// The function onload is loaded when the DOM has been loadeddocument.addEventListener("DOMContentLoaded", function () { new Game('renderCanvas');}, false); Game = function(canvasId) { var canvas = document.getElementById(canvasId); var engine = new BABYLON.Engine(canvas, true); this.scene = this._initScene(engine); var _this = this; this.loader = new BABYLON.AssetsManager(this.scene); // An array containing the loaded assets this.assets = {}; var meshTask = this.loader.addMeshTask("gun", "", "./assets/", "gun.babylon"); meshTask.onSuccess = function(task) { _this._initMesh(task); }; this.loader.onFinish = function (tasks) { // Player and arena creation when the loading is finished var player = new Player(_this); var arena = new Arena(_this); engine.runRenderLoop(function () { _this.scene.render(); }); window.addEventListener("keyup", function(evt) { _this.handleUserInput(evt.keyCode); }); }; this.loader.load(); // Resize the babylon engine when the window is resized window.addEventListener("resize", function () { if (engine) { engine.resize(); } },false); };Game.prototype = { /** * Init the environment of the game / skybox, camera, ... */ _initScene : function(engine) { var scene = new BABYLON.Scene(engine); /* Camera attached to the canvas var camera = new BABYLON.ArcRotateCamera("Camera", 0, Math.PI/5, 10, BABYLON.Vector3.Zero(), scene); camera.maxZ = 1000; camera.attachControl(engine.getRenderingCanvas()); */ axis(scene, 5); // Update the scene background color scene.clearColor=new BABYLON.Color3(0.8,0.8,0.8); // Hemispheric light to light the scene new BABYLON.HemisphericLight("hemi", new BABYLON.Vector3(1, 2, 1), scene); // Skydome var skybox = BABYLON.Mesh.CreateSphere("skyBox", 50, 1000, scene); skybox.layerMask = 2; // The sky creation BABYLON.Engine.ShadersRepository = "shaders/"; var shader = new BABYLON.ShaderMaterial("gradient", scene, "gradient", {}); shader.setFloat("offset", 200); shader.setColor3("topColor", BABYLON.Color3.FromInts(0,119,255)); shader.setColor3("bottomColor", BABYLON.Color3.FromInts(240,240, 255)); shader.backFaceCulling = false; skybox.material = shader; return scene; }, /** * Handle user keyboard inputs * @param keycode */ handleUserInput : function(keycode) { switch (keycode) { // user inputs } }, /** * Initialize a mesh once it has been loaded. Store it in the asset array and set it not visible. * @param task * @private */ _initMesh : function(task) { this.assets[task.name] = task.loadedMeshes; for (var i=0; i<task.loadedMeshes.length; i++ ){ var mesh = task.loadedMeshes[i]; mesh.isVisible = false; } }};/** * Draw axis on the scene * @param scene The scene where the axis will be displayed * @param size The size of each axis. */var axis = function(scene, size) { //X axis var x = BABYLON.Mesh.CreateCylinder("x", size, 0.1, 0.1, 6, scene, false); x.material = new BABYLON.StandardMaterial("xColor", scene); x.material.diffuseColor = new BABYLON.Color3(1, 0, 0); x.position = new BABYLON.Vector3(size/2, 0, 0); x.rotation.z = Math.PI / 2; //Y axis var y = BABYLON.Mesh.CreateCylinder("y", size, 0.1, 0.1, 6, scene, false); y.material = new BABYLON.StandardMaterial("yColor", scene); y.material.diffuseColor = new BABYLON.Color3(0, 1, 0); y.position = new BABYLON.Vector3(0, size / 2, 0); //Z axis var z = BABYLON.Mesh.CreateCylinder("z", size, 0.1, 0.1, 6, scene, false); z.material = new BABYLON.StandardMaterial("zColor", scene); z.material.diffuseColor = new BABYLON.Color3(0, 0, 1); z.position = new BABYLON.Vector3(0, 0, size/2); z.rotation.x = Math.PI / 2;}; This is weapon.js (gives me this error: "Uncaught ReferenceError: engine is not defined")where am I wrong?Weapon = function(game, player) { this.game = game; this.player = player; // The weapon mesh var wp = game.assets["gun"][0]; wp.isVisible = true; wp.rotationQuaternion = null; wp.rotation.x = -Math.PI/2; wp.rotation.y = Math.PI; wp.parent = player.camera; wp.position = new BABYLON.Vector3(0.25,-0.4,1); this.mesh = wp; // The initial rotation this._initialRotation = this.mesh.rotation.clone(); // The fire rate this.fireRate = 250.0; this._currentFireRate = this.fireRate; this.canFire = true; // The particle emitter var scene = this.game.scene; var particleSystem = new BABYLON.ParticleSystem("particles", 100, scene ); particleSystem.emitter = this.mesh; // the starting object, the emitter particleSystem.particleTexture = new BABYLON.Texture("./assets/particles/gunshot_125.png", scene); particleSystem.emitRate = 5; particleSystem.blendMode = BABYLON.ParticleSystem.BLENDMODE_STANDARD; particleSystem.minEmitPower = 1; particleSystem.maxEmitPower = 3; particleSystem.colorDead = new BABYLON.Color4(1, 1, 1, 0.0); particleSystem.minLifeTime = 0.2; particleSystem.maxLifeTime = 0.2; particleSystem.updateSpeed = 0.02; //particleSystem.start(); this.particleSystem = particleSystem; var _this = this; this.game.scene.registerBeforeRender(function() { if (!_this.canFire) { _this._currentFireRate -= engine.GetDeltaTime(); // _this._currentFireRate -= BABYLON.Tools.GetDeltaTime(); if (_this._currentFireRate <= 0) { _this.canFire = true; _this._currentFireRate = _this.fireRate; } } }); };Weapon.prototype = { /** * Animate the weapon */ animate : function() { this.particleSystem.start(); var start = this._initialRotation.clone(); var end = start.clone(); end.x += Math.PI/10; // Create the Animation object var display = new BABYLON.Animation( "fire", "rotation", 60, BABYLON.Animation.ANIMATIONTYPE_VECTOR3, BABYLON.Animation.ANIMATIONLOOPMODE_CONSTANT); // Animations keys var keys = [{ frame: 0, value: start },{ frame: 10, value: end },{ frame: 100, value: start }]; // Add these keys to the animation display.setKeys(keys); // Link the animation to the mesh this.mesh.animations.push(display); // Run the animation ! var _this = this; this.game.scene.beginAnimation(this.mesh, 0, 100, false, 10, function() { _this.particleSystem.stop(); }); }, /** * Fire the weapon if possible. * The mesh is animated and some particles are emitted. */ fire : function(pickInfo) { if (this.canFire) { if (pickInfo.hit && pickInfo.pickedMesh.name === "target") { pickInfo.pickedMesh.explode(); } else { var b = BABYLON.Mesh.CreateBox("box", 1, this.game.scene); b.position = pickInfo.pickedPoint.clone(); b.checkCollisions = true; } this.animate(); this.canFire = false; } else { // Nothing to do : cannot fire } }}; Quote Link to comment Share on other sites More sharing options...
iiceman Posted February 4, 2015 Share Posted February 4, 2015 You could define engine outside your classes to make it a global variable that can be accessed from everywhere or you hand the engine variable to your weapon constructor when creating that class.Weapon = function(game, player, engine) { ...}So when you initiate the Weapon, you could pass the engine as a parameter... but I didn't see where you create that weapon... not sure what's the better way of doing it. But you get the idea? bombe93 1 Quote Link to comment Share on other sites More sharing options...
bombe93 Posted February 4, 2015 Author Share Posted February 4, 2015 Thanks iiceman! I had not thought, I solved in 10 seconds! Now I'm trying to integrate the jump but gives me an error on the scene ("Uncaught TypeError: Cannot read property 'cameras' of undefined"). This is the file Player.js where I want to add the jump:/** * A player is represented by a box and a free camera. * @param scene * @param game * @param spawnPoint The spawning point of the player * @constructor */Player = function(game, spawnPoint) { if (!spawnPoint) { spawnPoint = new BABYLON.Vector3(0,10,-10); } // The player spawnPoint this.spawnPoint = spawnPoint; // The game scene this.scene = game.scene; // The game this.game = game; // The player eyes height this.height = 2; // The player speed this.speed = 1; // The player inertia this.inertia = 0.9; // The player angular inertia this.angularInertia = 0; // The mouse sensibility (lower the better sensible) this.angularSensibility = 4000; // The player camera this.camera = this._initCamera(); // The player must click on the canvas to activate control this.controlEnabled = false; // The player weapon this.weapon = new Weapon(game, this,this.scene.getEngine()); var _this = this; var canvas = this.scene.getEngine().getRenderingCanvas(); // Event listener on click on the canvas canvas.addEventListener("click", function(evt) { var width = _this.scene.getEngine().getRenderWidth(); var height = _this.scene.getEngine().getRenderHeight(); if (_this.controlEnabled) { var pickInfo = _this.scene.pick(width/2, height/2, null, false, _this.camera); _this.handleUserMouse(evt, pickInfo); } }, false); // Event listener to go pointer lock this._initPointerLock(); // The representation of player in the minimap var s = BABYLON.Mesh.CreateSphere("player2", 16, 8, this.scene); s.position.y = 10; s.registerBeforeRender(function() { s.position.x = _this.camera.position.x; s.position.z = _this.camera.position.z; }); var red = new BABYLON.StandardMaterial("red", this.scene); red.diffuseColor = BABYLON.Color3.Red(); red.specularColor = BABYLON.Color3.Black(); s.material = red; s.layerMask = 1; // Set the active camera for the minimap this.scene.activeCameras.push(this.camera); this.scene.activeCamera = this.camera;};Player.prototype = { _initPointerLock : function() { var _this = this; // Request pointer lock var canvas = this.scene.getEngine().getRenderingCanvas(); canvas.addEventListener("click", function(evt) { canvas.requestPointerLock = canvas.requestPointerLock || canvas.msRequestPointerLock || canvas.mozRequestPointerLock || canvas.webkitRequestPointerLock; if (canvas.requestPointerLock) { canvas.requestPointerLock(); } }, false); // Event listener when the pointerlock is updated. var pointerlockchange = function (event) { _this.controlEnabled = (document.mozPointerLockElement === canvas || document.webkitPointerLockElement === canvas || document.msPointerLockElement === canvas || document.pointerLockElement === canvas); if (!_this.controlEnabled) { _this.camera.detachControl(canvas); } else { _this.camera.attachControl(canvas); } }; document.addEventListener("pointerlockchange", pointerlockchange, false); document.addEventListener("mspointerlockchange", pointerlockchange, false); document.addEventListener("mozpointerlockchange", pointerlockchange, false); document.addEventListener("webkitpointerlockchange", pointerlockchange, false); }, /** * Init the player camera * @returns {BABYLON.FreeCamera} * @private */ _initCamera : function() { var cam = new BABYLON.FreeCamera("camera", this.spawnPoint, this.scene); cam.attachControl(this.scene.getEngine().getRenderingCanvas()); cam.ellipsoid = new BABYLON.Vector3(2, this.height, 2); cam.checkCollisions = true; cam.applyGravity = true; window.addEventListener("keyup", onKeyUp, false); function onKeyUp(event) { switch (event.keyCode) { case 17: var camera = this.scene.cameras[0]; camera.animations = []; var a = new BABYLON.Animation("a", "position.y", 20, BABYLON.Animation.ANIMATIONTYPE_FLOAT, BABYLON.Animation.ANIMATIONLOOPMODE_CYCLE); // Animation keys var keys = []; keys.push({ frame: 0, value: camera.position.y }); keys.push({ frame: 10, value: camera.position.y + 2 }); keys.push({ frame: 20, value: camera.position.y }); a.setKeys(keys); var easingFunction = new BABYLON.CircleEase(); easingFunction.setEasingMode(BABYLON.EasingFunction.EASINGMODE_EASEINOUT); a.setEasingFunction(easingFunction); camera.animations.push(a); this.scene.beginAnimation(camera, 0, 20, false); break; } } // ZQSD cam.keysUp = [87]; // Z cam.keysDown = [83]; // S cam.keysLeft = [65]; // Q cam.keysRight = [68]; // D cam.speed = this.speed; cam.inertia = this.inertia; cam.angularInertia = this.angularInertia; cam.angularSensibility = this.angularSensibility; cam.layerMask = 2; return cam; }, /** * Handle the user input on keyboard * @param keycode */ handleUserKeyboard : function(keycode) { switch (keycode) { } }, /** * Handle the user input on mouse. * click = shoot * @param evt * @param pickInfo The pick data retrieved when the click has been done */ handleUserMouse : function(evt, pickInfo) { this.weapon.fire(pickInfo); } }; Quote Link to comment Share on other sites More sharing options...
iiceman Posted February 4, 2015 Share Posted February 4, 2015 I think the error is a reference to this line: var camera = this.scene.cameras[0];Try changing it to:var camera = cam;... since that is the variable name of your camera. Alternatively you could remove that line and rename all appearances of camera to cam. Good luck, hope it works Quote Link to comment Share on other sites More sharing options...
bombe93 Posted February 4, 2015 Author Share Posted February 4, 2015 Now gives me this error "Uncaught TypeError: Cannot set property 'animations' of undefined" in this line "camera.animations = []; " Quote Link to comment Share on other sites More sharing options...
iiceman Posted February 4, 2015 Share Posted February 4, 2015 Well.. what did you do? You used the line: "var camera = cam;"? Right above the line that trows the error? Quote Link to comment Share on other sites More sharing options...
bombe93 Posted February 4, 2015 Author Share Posted February 4, 2015 Yes i used "var camera = cam;" Quote Link to comment Share on other sites More sharing options...
iiceman Posted February 4, 2015 Share Posted February 4, 2015 Then I don't really know... you can just do some debugging out puts with console.log to see if it is really undefined and then find out why... check if your variable cam is set or where the error actually happens. Sorry, it's kinda hard for me when I can't really play with the code :-/ Quote Link to comment Share on other sites More sharing options...
bombe93 Posted February 4, 2015 Author Share Posted February 4, 2015 In this way does not give me any error but nothing happens UPDATE: "onKeyUp" function does not work if I try to pass variables (like camera).I think gives me this error because it seems to be an isolated function and therefore does not take the variables that I need as the camera. (the jump function is at 114 line number)/** * A player is represented by a box and a free camera. * @param scene * @param game * @param spawnPoint The spawning point of the player * @constructor */Player = function(game, spawnPoint) { if (!spawnPoint) { spawnPoint = new BABYLON.Vector3(0,10,-10); } // The player spawnPoint this.spawnPoint = spawnPoint; // The game scene this.scene = game.scene; // The game this.game = game; // The player eyes height this.height = 2; // The player speed this.speed = 1; // The player inertia this.inertia = 0.9; // The player angular inertia this.angularInertia = 0; // The mouse sensibility (lower the better sensible) this.angularSensibility = 4000; // The player camera this.camera = this._initCamera(); // The player must click on the canvas to activate control this.controlEnabled = false; // The player weapon this.weapon = new Weapon(game, this,this.scene.getEngine()); var _this = this; var canvas = this.scene.getEngine().getRenderingCanvas(); // Event listener on click on the canvas canvas.addEventListener("click", function(evt) { var width = _this.scene.getEngine().getRenderWidth(); var height = _this.scene.getEngine().getRenderHeight(); if (_this.controlEnabled) { var pickInfo = _this.scene.pick(width/2, height/2, null, false, _this.camera); _this.handleUserMouse(evt, pickInfo); } }, false); // Event listener to go pointer lock this._initPointerLock(); // The representation of player in the minimap var s = BABYLON.Mesh.CreateSphere("player2", 16, 8, this.scene); s.position.y = 10; s.registerBeforeRender(function() { s.position.x = _this.camera.position.x; s.position.z = _this.camera.position.z; }); var red = new BABYLON.StandardMaterial("red", this.scene); red.diffuseColor = BABYLON.Color3.Red(); red.specularColor = BABYLON.Color3.Black(); s.material = red; s.layerMask = 1; // Set the active camera for the minimap this.scene.activeCameras.push(this.camera); this.scene.activeCamera = this.camera;};Player.prototype = { _initPointerLock : function() { var _this = this; // Request pointer lock var canvas = this.scene.getEngine().getRenderingCanvas(); canvas.addEventListener("click", function(evt) { canvas.requestPointerLock = canvas.requestPointerLock || canvas.msRequestPointerLock || canvas.mozRequestPointerLock || canvas.webkitRequestPointerLock; if (canvas.requestPointerLock) { canvas.requestPointerLock(); } }, false); // Event listener when the pointerlock is updated. var pointerlockchange = function (event) { _this.controlEnabled = (document.mozPointerLockElement === canvas || document.webkitPointerLockElement === canvas || document.msPointerLockElement === canvas || document.pointerLockElement === canvas); if (!_this.controlEnabled) { _this.camera.detachControl(canvas); } else { _this.camera.attachControl(canvas); } }; document.addEventListener("pointerlockchange", pointerlockchange, false); document.addEventListener("mspointerlockchange", pointerlockchange, false); document.addEventListener("mozpointerlockchange", pointerlockchange, false); document.addEventListener("webkitpointerlockchange", pointerlockchange, false); }, /** * Init the player camera * @returns {BABYLON.FreeCamera} * @private */ _initCamera : function() { var cam = new BABYLON.FreeCamera("camera", this.spawnPoint, this.scene); cam.attachControl(this.scene.getEngine().getRenderingCanvas()); cam.ellipsoid = new BABYLON.Vector3(2, this.height, 2); cam.checkCollisions = true; cam.applyGravity = true; window.addEventListener("keyup", onKeyUp(cam), false); function onKeyUp(event,camera) { switch (event.keyCode) { case 17: //var camera = cam; camera.animations = []; var a = new BABYLON.Animation("a", "position.y", 20, BABYLON.Animation.ANIMATIONTYPE_FLOAT, BABYLON.Animation.ANIMATIONLOOPMODE_CYCLE); // Animation keys var keys = []; keys.push({ frame: 0, value: camera.position.y }); keys.push({ frame: 10, value: camera.position.y + 2 }); keys.push({ frame: 20, value: camera.position.y }); a.setKeys(keys); var easingFunction = new BABYLON.CircleEase(); easingFunction.setEasingMode(BABYLON.EasingFunction.EASINGMODE_EASEINOUT); a.setEasingFunction(easingFunction); camera.animations.push(a); this.scene.beginAnimation(camera, 0, 20, false); var cam = this.scene.cameras[0]; cam.animations = []; var a = new BABYLON.Animation( "a", "position.y", 20, BABYLON.Animation.ANIMATIONTYPE_FLOAT, BABYLON.Animation.ANIMATIONLOOPMODE_CYCLE); // Animation keys var keys = []; keys.push({ frame: 0, value: cam.position.y }); keys.push({ frame: 10, value: cam.position.y + 2 }); keys.push({ frame: 20, value: cam.position.y }); a.setKeys(keys); var easingFunction = new BABYLON.CircleEase(); easingFunction.setEasingMode(BABYLON.EasingFunction.EASINGMODE_EASEINOUT); a.setEasingFunction(easingFunction); cam.animations.push(a); scene.beginAnimation(cam, 0, 20, false); break; } } // ZQSD cam.keysUp = [87]; // Z cam.keysDown = [83]; // S cam.keysLeft = [65]; // Q cam.keysRight = [68]; // D cam.speed = this.speed; cam.inertia = this.inertia; cam.angularInertia = this.angularInertia; cam.angularSensibility = this.angularSensibility; cam.layerMask = 2; return cam; }, /** * Handle the user input on keyboard * @param keycode */ handleUserKeyboard : function(keycode) { switch (keycode) { } }, /** * Handle the user input on mouse. * click = shoot * @param evt * @param pickInfo The pick data retrieved when the click has been done */ handleUserMouse : function(evt, pickInfo) { this.weapon.fire(pickInfo); } }; Quote Link to comment Share on other sites More sharing options...
iiceman Posted February 5, 2015 Share Posted February 5, 2015 You should be able to access cam from within the event function even without passing the cam variable. Your cam variable is defined outside that function, so it is on a higher level and should be available on lower levels, too, unless you overwrite it. So don't try to pass it there. Just check if you can access it from within the event function. I still don't really understand your code I fear :-/ How many cameras do you actually have? Just one? May I ask: did you write that code yourself? You don't have a git repository with the whole project that I just could clone and try out myself, do you? Or maybe you can upload everything to a server and I can get the whole thing from there and take a look? Quote Link to comment Share on other sites More sharing options...
bombe93 Posted February 5, 2015 Author Share Posted February 5, 2015 You should be able to access cam from within the event function even without passing the cam variable. Your cam variable is defined outside that function, so it is on a higher level and should be available on lower levels, too, unless you overwrite it. So don't try to pass it there. Just check if you can access it from within the event function. it's what I think! I still don't really understand your code I fear :-/ How many cameras do you actually have? Just one? May I ask: did you write that code yourself? The code does not wrote it, but I'm trying to improve it by adding new things(like jump).I think there are 2 cameras, one for player and the other for the minimap. You don't have a git repository with the whole project that I just could clone and try out myself, do you? Or maybe you can upload everything to a server and I can get the whole thing from there and take a look? Here is the link: https://github.com/Bombe93/Babylon-test Quote Link to comment Share on other sites More sharing options...
bombe93 Posted February 5, 2015 Author Share Posted February 5, 2015 I solved!The problem is that the function _initCamera is private so I had to create a new variable scene(in this way the cam works, "var camera = cam;"): _initCamera : function() { var cam = new BABYLON.FreeCamera("camera", this.spawnPoint, this.scene); cam.attachControl(this.scene.getEngine().getRenderingCanvas()); cam.ellipsoid = new BABYLON.Vector3(2, this.height, 2); cam.checkCollisions = true; cam.applyGravity = true; var sceneJump = this.scene; window.addEventListener("keyup", onKeyUp, false); function onKeyUp(event) { switch (event.keyCode) { case 17: var camera = cam; camera.animations = []; var a = new BABYLON.Animation("a", "position.y", 20, BABYLON.Animation.ANIMATIONTYPE_FLOAT, BABYLON.Animation.ANIMATIONLOOPMODE_CYCLE); // Animation keys var keys = []; keys.push({ frame: 0, value: camera.position.y }); keys.push({ frame: 8, value: camera.position.y + 8 }); keys.push({ frame: 13, value: camera.position.y }); a.setKeys(keys); var easingFunction = new BABYLON.CircleEase(); easingFunction.setEasingMode(BABYLON.EasingFunction.EASINGMODE_EASEINOUT); a.setEasingFunction(easingFunction); console.log("entrato6"); camera.animations.push(a); sceneJump.beginAnimation(camera, 0, 20, false); break; } } Quote Link to comment Share on other sites More sharing options...
iiceman Posted February 5, 2015 Share Posted February 5, 2015 Uhm... okay.. well, glad it works now bombe93 1 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.