• Content Count

  • Joined

  • Last visited

  1. Flight movement solved in this playground: https://www.babylonjs-playground.com/#P394JW#3 Now quaternions make more sense for me 😊 I found that the problem I was facing is called "Gimbal Lock" using Euler Angles. But I still have a small problem: when rotating the X axis using quaternions, the rotation breaks on 90 degress/radians and -90 degress/radians. To "solve" it, I limited the X axis rotation to a max of 85 degrees/radians. Is there another way to avoid this issue? I noticed that this only occurs in X axis. Rotating on Y anz Z axis has no limitations and I can make full 360 degress rotations. To reproduce the problem, please modify the line 73 to more than 90 degrees, Eg: var maxPitchAngle = (120 * (Math.PI / 180)); Thanks for attention!!
  2. Hey guys, I'm trying to make a simple flight simulation, but I have some issues trying to rotate my plane. Currently, I have this code: EDIT: I created a playground to exemplify better my problem: https://www.babylonjs-playground.com/indexStable.html#HT1PHY#5 var elapsed = engine.getDeltaTime() / 1000; // handle keys if(keysDown[87]) { // W, rotate in the negative direction about the x axis pitch += elapsed * turnSpeed; } if(keysDown[83]) { // S, rotate in the positive direction about the x axis pitch -= elapsed * turnSpeed; } if(keysDown[65]) { // A, rotate left yaw -= elapsed * turnSpeed; roll += elapsed * turnSpeed; } if(keysDown[68]) { // D, rotate right yaw += elapsed * turnSpeed; roll -= elapsed * turnSpeed; } var translationVector = new BABYLON.Vector3(0, 0, 1).normalize(); var rotationQuaternion = BABYLON.Quaternion.RotationYawPitchRoll(yaw, pitch, roll); // Apllying translation and rotation to the plane controlCraft.rotationQuaternion = rotationQuaternion; controlCraft.translate(translationVector, elapsed + airSpeed, BABYLON.Space.LOCAL); I want to rotate the plane ever considering its "Forward Axis", but when I rotate it to the left or right and press W/S, the pitch doesn't work correctly and the plane yaws, instead of pitching. How can I fix it? I'm trying to make it with Quaternions, but I don't know the correct path. Thanks very much for the help!!
  3. Thanks @Deltakosh!!
  4. Is there any way to save a screenshot with this layer of background? I am using BABYLON.Tools.CreateScreenshot but always creates an image with a transparent background. For now, I'm using canvas.toDataURL ("image / png"), keeping the preserveDrawingBuffer to true to be able to save the full picture. Thanks
  5. This is Awesome!!! Thanks very much @Wingnut!! This works perfectly for me.
  6. Hi, I have an application that uses BabylonJS: http://rapidmockup.topempresas.net/ As you see, i have a skybox with 3D backgrounds and a ArcRotateCamera in my scene. This works well, but i need a second behavior in my scene. When the user select an option, i need to rotate only the object and the plane in my scene, but not the background. It is because i need a option to user add your own backgorund image, but users will upload only one texture, and the background skybox must be fixed to see only one face. Is it possible? How to make it? Thanks by the support!
  7. Thanks @dungtm. I will scan my code for references. Thanks a lot for your help!!
  8. I have a similar problem with my app (using NW.js to run in Desktop Mode) . When i click a button, I call the code below: resetScene: function(meshName) { scene.dispose(); return this.createNewScene(meshName); //Creates a new scene } The scene.dispose() works well, but the memory is not released. And I have the same problem with material.dispose(), always that i call it, the memory is not released. When I create a new material, the memory increases. What can i do to solve this? Thanks a lot
  9. Hello guys, I'm making my first game using Phaser, but i have a problem. The idea is: the player guide a yellow monster to eat the food taht falls from the screen. When the player eat, should immediately drop a new food. The problem is that sometimes the food takes to fall. I changed several things in the code, but got no result. Thank you for your attention Play de game: http://tiagosilvapereira.esy.es/Scroller/ window.onload = function(){ var width = navigator.isCocoonJS ? window.innerWidth : 640, height = navigator.isCocoonJS ? window.innerHeight : 960; game = new Phaser.Game(width, height, Phaser.AUTO, '', { preload: loadAssets, create: createScenario, update: updateGame });}var score = 0;var life = 100;var life_dec = 5;var food_velocity = 400;var food_position_x = 0;var food_value = 5;var left=false;var right=false;function loadAssets(){ game.time.advancedTiming = true; game.load.image('background', 'assets/background.png'); game.load.image('player', 'assets/player.png'); game.load.image('food', 'assets/food.png'); game.load.spritesheet('btn_left', 'assets/btn_left.png', 64, 64); game.load.spritesheet('btn_right', 'assets/btn_right.png', 64, 64);}function createScenario(){ //if (!game.device.desktop){ game.input.onDown.add(gofull, this); } //game.device.cocoonJS = true; //game.device.android = true; game.input.maxPointer = 1; //Desabilita o multitoque game.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL; game.scale.pageAlignHorizontally = true; game.scale.pageAlignVertically = true; game.scale.setScreenSize(true); game.physics.startSystem(Phaser.Physics.ARCADE); cursors = game.input.keyboard.createCursorKeys(); buttonleft = game.add.button(0, 900, 'btn_left', null, this, 0, 1, 0, 1); buttonleft.fixedToCamera = true; buttonleft.events.onInputOver.add(function(){left=true; right = false;}); buttonleft.events.onInputOut.add(function(){left=false;}); buttonleft.events.onInputDown.add(function(){left=true; right = false;}); buttonleft.events.onInputUp.add(function(){left=false;}); buttonright = game.add.button(576, 900, 'btn_right', null, this, 0, 1, 0, 1); buttonright.fixedToCamera = true; buttonright.events.onInputOver.add(function(){right=true; left = false;}); buttonright.events.onInputOut.add(function(){right=false;}); buttonright.events.onInputDown.add(function(){right=true; left = false;}); buttonright.events.onInputUp.add(function(){right=false;}); createBackground(); food = game.add.group(); food.enableBody = true; createPlayer(); createFood(); scoreText = game.add.text(10, 10, 'Score: 0', {font: "20px Arial", fill: "#ffffff", align: "left"}); lifeText = game.add.text(10, 50, 'Life: 100', {font: "20px Arial", fill: "#ff7700", align: "left"}); game.time.events.loop(2000, decLife, this);}// Atualiza o jogo - 60fpsfunction updateGame(){ lifeText.text = 'Life: ' + life; if(life <= 0){ var text = game.add.text(game.camera.width / 2 - 100, game.camera.height / 2, "GAME OVER", { font: "30px Arial", fill: "#ff0044", align: "center" }); } player.body.velocity.x = 0; moveFood(food_velocity); game.physics.arcade.overlap(player, food, overlapFood); if (cursors.left.isDown || left == true){ player.body.velocity.x = -1500; }else if (cursors.right.isDown || right == true){ player.body.velocity.x = 1500; } game.debug.text(game.time.fps || '--', 600, 14, "#00ff00");}function createBackground(){ game.add.sprite(0, 0, 'background');}function createPlayer(){ player = game.add.sprite(game.world.centerX - 16, game.world.height - 200, 'player'); game.physics.arcade.enable(player); player.body.collideWorldBounds = true;}function overlapFood(){ food01.body.position.y = 0; randomFoodPos(); food01.body.position.x = food_position_x; if(food_velocity < 2500){ food_velocity += 10; } if(life < 100){ life += food_value; }else{ life = 100; } score++; scoreText.text = 'Score: ' + score;}// Cria as plataformasfunction createFood(){ randomFoodPos(); food01 = food.create(food_position_x, 0, 'food');}function moveFood(speed){ food01.body.velocity.y = speed; if(food01.body.position.y >= 960){ food01.body.position.y = 0; randomFoodPos(); food01.body.position.x = food_position_x; }}function randomFoodPos(){ food_position_x = game.rnd.integerInRange(32, game.world.width - 32);}function decLife(){ // Decrementa a vida do player if(life > 0){ life -= life_dec; }else life = 0;}