tranlong021988 Posted April 18, 2016 Share Posted April 18, 2016 hi everyone , I'm very new with BabylonJS , I 'm building my first game with this engine. The gameplay, is a little bit with Assansin Creed demo : http://race.assassinscreedpirates.com/ My game have difference: it's target mobile browser with VR technology. Player will use CardBoard to navigate their jet. Thanks to VRDeviceOrientationFreeCamera , I can set it up easily to visualize 3d viewer in my game. The only problem is I did set jet rotation same with camera rotation, everything work fine on PC but on mobile browser, if I (and my card board) look higher, the jet direction come "flip" so it make my jet go wrong way. This is my code: scene.registerBeforeRender(function(){ // make jet go base on its rotation. var deg = jet.rotation.y*180/Math.PI - 90; jet.position.x+=0.1*Math.cos(deg*Math.PI/180); jet.position.z-=0.1*Math.sin(deg*Math.PI/180); // place camera behind the jet ("always"). scene.activeCamera.position.x = jet.position.x+1*Math.cos((deg-180)*Math.PI/180); scene.activeCamera.position.z = jet.position.z-1*Math.sin((deg-180)*Math.PI/180); // set jet rotation same with camera rotation. jet.rotation.y = scene.activeCamera.rotation.y; })},false); I think because of activeCamera.roation.y input by mobile device orientation is different with PC. But I have no idea about device orientation , so anyone can help me ? this is what I get til now: https://dl.dropboxusercontent.com/u/86585940/BabylonWave/index.html , just try it on mobile browser with landscape mode. Sorry for my poor English. Quote Link to comment Share on other sites More sharing options...
Flomotion Posted April 18, 2016 Share Posted April 18, 2016 Hi, I had the exact same problem when trying to move the camera in the direction it was looking. Axes were flipping when the head is looking up. I made an ugly (but working fix). Hope it helps a bit. if (Math.abs(camera.rotation.x)>2 && Math.abs(camera.rotation.z)>2) { camSpeed = camSpeed*-1; camera.rotation.z = Math.abs(camera.rotation.z*-1); } tranlong021988 1 Quote Link to comment Share on other sites More sharing options...
tranlong021988 Posted April 18, 2016 Author Share Posted April 18, 2016 6 hours ago, Flomotion said: Hi, I had the exact same problem when trying to move the camera in the direction it was looking. Axes were flipping when the head is looking up. I made an ugly (but working fix). Hope it helps a bit. if (Math.abs(camera.rotation.x)>2 && Math.abs(camera.rotation.z)>2) { camSpeed = camSpeed*-1; camera.rotation.z = Math.abs(camera.rotation.z*-1); } thanks for answering me, I did firgure out that flipped issue happened by rotation of camera if value > 1 , so I make a condiction code: if(scene.activeCamera.rotation.x<1){ jet.rotation.y = scene.activeCamera.rotation.y; }else{ jet.rotation.y = scene.activeCamera.rotation.y+Math.PI; } now it work well. GameMonetize 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.