Borislav Posted April 10, 2017 Share Posted April 10, 2017 I want to make a character that moves by "W" "A" "S" "D" and "Up" "Left" "Down" "Right" being pressed. But seriously, HOW?!! I even did a test with Clicking controls; but it didn't work! >;o I can't find the tutorial in the web please help!! Quote Link to comment Share on other sites More sharing options...
JohnK Posted April 10, 2017 Share Posted April 10, 2017 Is this of help? http://www.babylonjs-playground.com/#102TBD#33 This method allows for two keys pressed at once but one at a time is ok. Lines 139 to 149 check for keys down or up, action for keys in registerAfterRender loop. Quote Link to comment Share on other sites More sharing options...
Borislav Posted April 10, 2017 Author Share Posted April 10, 2017 34 minutes ago, JohnK said: Is this of help? http://www.babylonjs-playground.com/#102TBD#33 This method allows for two keys pressed at once but one at a time is ok. Lines 139 to 149 check for keys down or up, action for keys in registerAfterRender loop. It is actionmanager, okay... But; this is something different I am wanting the character to move and this all is really confusing since there are some ifs and e.t.c... Do you know how to simply make something like an object moving? Quote Link to comment Share on other sites More sharing options...
JohnK Posted April 11, 2017 Share Posted April 11, 2017 Only way I know is with the ifs if(map["W"] || map["w"]) { character.position.y +=5; } Have a go at a simple playground and ask again if necessary. You can find a more on using actions and using keys as triggers at http://doc.babylonjs.com/tutorials/how_to_use_actions#triggers (again more ifs - they really are needed) Basic character control using keys with javascript at http://www.gaminglogy.com/tutorial/controls-keyboard/ Quote Link to comment Share on other sites More sharing options...
Raggar Posted April 11, 2017 Share Posted April 11, 2017 16 hours ago, Borislav said: Do you know how to simply make something like an object moving? Like this?: http://www.babylonjs-playground.com/#Z7U9QE If you need physics, collision detection etc. you'll need a physics engine, too. Babylon has built-in tools for that. You won't exactly come a long way without if statements and conditions, so if they confuse you, read up on them. There are millions of resources for just that. Quote Link to comment Share on other sites More sharing options...
Borislav Posted April 11, 2017 Author Share Posted April 11, 2017 2 hours ago, Raggar said: Like this?: http://www.babylonjs-playground.com/#Z7U9QE If you need physics, collision detection etc. you'll need a physics engine, too. Babylon has built-in tools for that. You won't exactly come a long way without if statements and conditions, so if they confuse you, read up on them. There are millions of resources for just that. Fantastic, just what I needed! I have a physics engine :). Thank you. Quote Link to comment Share on other sites More sharing options...
Borislav Posted April 11, 2017 Author Share Posted April 11, 2017 4 hours ago, JohnK said: Only way I know is with the ifs if(map["W"] || map["w"]) { character.position.y +=5; } Have a go at a simple playground and ask again if necessary. You can find a more on using actions and using keys as triggers at http://doc.babylonjs.com/tutorials/how_to_use_actions#triggers (again more ifs - they really are needed) Basic character control using keys with javascript at http://www.gaminglogy.com/tutorial/controls-keyboard/ I meant that it is like: if(d = || asa = sft||Fds) Quote Link to comment Share on other sites More sharing options...
JohnK Posted April 11, 2017 Share Posted April 11, 2017 || means or if (evt.keyCode==68 || evt.keyCode == 100){ //D or d Quote Link to comment Share on other sites More sharing options...
Wingnut Posted April 11, 2017 Share Posted April 11, 2017 Hi guys, sorry to butt-in. @Borislav (and anyone else interested)... I once created a strange keypress listener system. It is different and somewhat weird. http://playground.babylonjs.com/#2DYPYK#6 Weird, but easy to program... maybe. Put lines 17-44 into your code. You MUST have jQuery installed, because of lines 103-104. I THINK that can be changed... so you don't need jQuery. Haven't tried. Also include lines 101-116... in your project. Notice how I create a "movement function" such-as rotateCCW() in lines 90-94. After that function, you see... keymaster.csz = rotateCCW; keymaster.sz = rotateCCW; keymaster.z = rotateCCW; That means... control-shift-z (csz), AND shift-z (sz) AND z ... all will run rotateCCW() function. Understand? I hope so, because I really don't. This system is NOT WELL TESTED AT ALL. You have been warned. But, somehow, it works, and it's easy, and nice code to read. NO PROMISES about how intelligent this is. Possibly dangerous. Might blow up. heh. Keymaster property names... must have their "characters" in alphabetical order. a=alt, c=control, m=meta, s=shift... and of course, bucky-less (plain ol' z). Borrow at-will. It is MOSTLY made for projects that have MANY MANY keypresses allowed. AND... perhaps avoid ALT. In recent tests, using ALT key caused "mesh not found" errors. Not sure why, yet. Also, control-shift-w is Windows "close this window" hotkey, and I haven't learned how to stop it, yet. So, maybe avoid control-shift-w, for now. Party on! Quote Link to comment Share on other sites More sharing options...
Raggar Posted April 11, 2017 Share Posted April 11, 2017 10 hours ago, Borislav said: Fantastic, just what I needed! I have a physics engine :). Thank you. If you use a physics engine, it is encouraged to use velocities to move around, instead of moving the bodies at some fixed units. Wingnut 1 Quote Link to comment Share on other sites More sharing options...
Borislav Posted April 12, 2017 Author Share Posted April 12, 2017 14 hours ago, Raggar said: If you use a physics engine, it is encouraged to use velocities to move around, instead of moving the bodies at some fixed units. There are some glitches but that is an another story.. Quote Link to comment Share on other sites More sharing options...
Borislav Posted April 12, 2017 Author Share Posted April 12, 2017 23 hours ago, JohnK said: || means or if (evt.keyCode==68 || evt.keyCode == 100){ //D or d I know, I learned that while learning C++. 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.