Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

Velocity dissappears player?


xronn
 Share

Recommended Posts

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

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

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

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...