ID:2213169
 
Code:
forum_accounts keyboard lib
&
client
key_down()

key_repeat()

New()
..()
spawn()
movement_loop()

proc
movement_loop()
while(1)
sleep(world.tick_lag)
move()

move()
var/d = 0

if(keys["shift"])
mob.running = 1
else mob.running = 0

if(keys["w"]) d |= NORTH
if(keys["s"]) d |= SOUTH
if(keys["d"]) d |= EAST
if(keys["a"]) d |= WEST

if(!mob.running)
mob.icon_state = ""
mob.step_size = 3
else
mob.icon_state = "run"
mob.step_size = mob.movementspeed

if(mob.slowed == 1)
mob.step_size = mob.step_size/2

if(mob.slowed == 2)
return

step(mob, d)


Problem description:
Okay so everything works fine except for when you press 2 opposite directions like if I pressed East & West it'll make me face South and run either east or west, I'd really like it if it didn't face south XD, I'm not all that great of a programmer so I could really use the help fixing this XD
Deviant Coder wrote:
The reason why its making you face south is because it does not understand what you mean when you want to go EAST & WEST.

A proper fix to this is by implementing your own handle for EAST & WEST as well as SOUTH & NORTH.

> //Old Handle
> if(keys["w"]) d |= NORTH
> if(keys["s"]) d |= SOUTH
> if(keys["d"]) d |= EAST
> if(keys["a"]) d |= WEST
>

> //New Handle
> if(keys["w"]&&keys["s"]) //If north and south
> //Decide how its handled here.
> else
> if(keys["w"]) d |= NORTH
> if(keys["s"]) d |= SOUTH
> if(keys["d"]&&keys["a"]) //If west and east
> //Decide how its handled here.
> else
> if(keys["d"]) d |= EAST
> if(keys["a"]) d |= WEST
>

Personally, unless there was some type of velocity in play, I would let the player completely stop (vertically) if north and south was both pressed. Same with west and east.

Thank you very much, yeah I agree, it's now that way so it completely stops. :) It's perfect now thanks a lot