xronn Posted August 31, 2014 Share Posted August 31, 2014 So I'm using Velocity.x & y to move my player across the screen or so I would like but as soon as you touch either the left, or right arrow key the player disappears. Which is a little strange? if (this.cursor.left) { this.tank.body.velocity.x = -1; console.log('Trying to move left'); } else if (this.cursor.right) { this.tank.body.velocity.x = 1; } if (this.cursor.up) { this.tank.body.velocity.y = -1; } else { this.tank.body.velocity.y = 0; this.tank.body.velocity.x = 0; }Values are set to 1 to ensure the player didn't go flying off the screen instantly (does have collide with world borders anyway) Live Demo Link to comment Share on other sites More sharing options...
rich Posted August 31, 2014 Share Posted August 31, 2014 Doesn't move at all for me when I tested your link. Also the 'else' block resetting the velocity isn't right - you should only reset the x velocity if the left or right key isn't being pressed, not the up key. Otherwise you will always have to press 'up' in order to move at all. Link to comment Share on other sites More sharing options...
JUL Posted August 31, 2014 Share Posted August 31, 2014 Same here, no effect while pressing arrow keys. Link to comment Share on other sites More sharing options...
xronn Posted August 31, 2014 Author Share Posted August 31, 2014 Doesn't move at all for me when I tested your link. Also the 'else' block resetting the velocity isn't right - you should only reset the x velocity if the left or right key isn't being pressed, not the up key. Otherwise you will always have to press 'up' in order to move at all.Oh, I cleared my cache and re-ran the demo and your right it doesn't move at all, which is strange. This is a correct way of moving a player so its a little odd. thanks for pointing out the resets, I'll remake the 0 velocity rules for no input when he actually starts moving. Link to comment Share on other sites More sharing options...
rich Posted August 31, 2014 Share Posted August 31, 2014 He'll never start moving with those resets in place, you cancel out the horizontal velocity immediately after setting it. Link to comment Share on other sites More sharing options...
xronn Posted August 31, 2014 Author Share Posted August 31, 2014 He'll never start moving with those resets in place, you cancel out the horizontal velocity immediately after setting it.Oh I meant I've already removed them and I'll remake them after he starts moving. The else was removed which is why I'm confused Link to comment Share on other sites More sharing options...
Recommended Posts