skalibran Posted February 19, 2015 Share Posted February 19, 2015 Hey there, its me again with two stupid questions I looked for many examples on the web to understand how I can execute code when a key is pressed. Unfortunetaly, nothing worked for me. Is there a easy way to do this? I just need something like if(key.A) { variableNumber = 1; } Then I want to check some variables, so I tried to use the console from the debug layer:console.log(varTest); The console still tells me only that the Babylon.js engine launched.Any way to feed the console? Thanks for help! Quote Link to comment Share on other sites More sharing options...
MarianG Posted February 19, 2015 Share Posted February 19, 2015 Hi, try this:var keys={letft:0,right:0,forward:0,back:0};window.addEventListener("keydown", handleKeyDown, false);window.addEventListener("keyup", handleKeyUp, false);function handleKeyDown(evt){ if (evt.keyCode==65){//A keys.left=1; } if (evt.keyCode==68){//D keys.right=1; } if (evt.keyCode==87){//W keys.forward=1; } if (evt.keyCode==83){//S keys.back=1; }}function handleKeyUp(evt){ if (evt.keyCode==65){ keys.left=0; } if (evt.keyCode==68){ keys.right=0; } if (evt.keyCode==87){ keys.forward=0; } if (evt.keyCode==83){ keys.back=0; }}and hereengine.runRenderLoop(function () { if (keys.left==1) { //move left } if (keys.right==1) { //move right } if (keys.back==1) { //move back } if (keys.forward==1) { //move forward }});Isn't the best, but is a solution. Quote Link to comment Share on other sites More sharing options...
skalibran Posted February 19, 2015 Author Share Posted February 19, 2015 This is exactly what I was looking for. Thanks! First question answered Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted February 19, 2015 Share Posted February 19, 2015 For question 2: use BABYLON.Tools.Log("blah") Quote Link to comment Share on other sites More sharing options...
skalibran Posted February 20, 2015 Author Share Posted February 20, 2015 Alright, thanks to you 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.