Zhob Posted March 3, 2016 Share Posted March 3, 2016 Hi, I'm currently working on a tile base RPG game using Phaser. function create(): controls = { up: game.input.keyboard.addKey(Phaser.Keyboard.Z), (...), shift: game.input.keyboard.addKey(Phaser.Keyboard.SHIFT) }; } If I press Z, my character needs to move and if I press SHIFT + Z, my character has to rotate towards the Z direction. function update() : if (controls.shift.isDown) { if (controls.up.isDown){ rotateCharacter(); } } else { if (controls.up.isDown){ moveCharacter(); } } Right now, when try to rotate my character using SHIFT + Z, it triggers the rotation AND the movement. If I press Z alone, the character moves as expected. I've tried checking if my SHIFT key was up but it didn't change anything. How can I achieve that? Thanks, in advance. Link to comment Share on other sites More sharing options...
fillmoreb Posted March 3, 2016 Share Posted March 3, 2016 Everything you've posted seems to be correct. I even made a quick jsFiddle to see if what you were doing works, and it does. https://jsfiddle.net/mub2ps0c/3/ Since your logic and function calls seem correct, my guess is that you are accidentally moving the character within the rotation function. Link to comment Share on other sites More sharing options...
Zhob Posted March 3, 2016 Author Share Posted March 3, 2016 (edited) Thank you! I didn't mention that I was working on a multiplayer game and seeing your fiddle made think that my mistake wasn't on the controls but rather on how I render other players on the map... Original issue solved then! Quick question : Characters have to move 46px by 46px. The only way I found was this kind of "hack" : if (controls.up.isDown){ if (controls.up._justUp) { moveCharacter(); // Moves the character by 46px in the direction } } I updated your fiddle here. Is there a better way to do this? Also, if you spam the key, the tween restarts so the character might have moved more than 46px (edit: and I don't want that). Edited March 3, 2016 by Zhob Quick edit Link to comment Share on other sites More sharing options...
fillmoreb Posted March 4, 2016 Share Posted March 4, 2016 If you really want to use tweens, I would do it like this: https://jsfiddle.net/mub2ps0c/5/ Link to comment Share on other sites More sharing options...
Zhob Posted March 4, 2016 Author Share Posted March 4, 2016 Wow, exactly what I need! Thanks a lot! Link to comment Share on other sites More sharing options...
Recommended Posts