ID:155110
 
Hello! I am working on a knockback system for my game and I was wondering how I would make it to where when the enemy is knocked back, they stay in the direction that they were facing when hit, instead of facing the direction they are being knocked back.
mob
proc/KnockBack(mob/M,direction,times2move as num)
spawn() //so we don't stop w/e is happening where this proc was called

for(times2move,times2move>0,times2move--)
if(!M)return
step(M,direction)
frozen = 1
flick("Pushed",src)
var/obj/a = new/obj/dirts
var/obj/b = new/obj/dirts
var/obj/c = new/obj/dirts
var/obj/d = new/obj/dirts
a.loc = M.loc
b.loc = M.loc
c.loc = M.loc
sleep(1)
frozen = 0


The code above(it is all put together in a weird way here but it is alot more cleaner in the code) makes the enemy get pushed back when they are hit, causing a dirt obj to appear under their feet for a short period of time until disapearing. Everything works very smoothly except for the fact that after the enemy stops being knocked back they are facing the direction that they had walked in, instead of facing the same direction as the knockback. Any ideas? anything will help! thank you!

Instead of using step(), which automatically sets the atom's dir to the direction of movement, use Move(). Move() accepts several argument:

NewLoc (required): The location to move to.
Dir (optional): The direction the object should face.
step_x & step_y (optional): (used for "pixel movement".)

In order to get the newloc argument, just call get_step(object_to_be_moved, direction_of_movement).
In response to IainPeregrine
Ah I see, what would I add to get_step? I have tried get_step(M,direction) but it says it has no effect and if I add the Move(NewLoc,Dir=0) DM tells me that NewLoc is an undefined var..hmm
In response to Icesword553344
Try reading about get_step() in the reference.

get_step() only gets the step for you (it returns the turf in that direction). You then have to supply that turf as the new loc to Move().

Like this:

var/destination = get_step(moving_thing, movement_direction)
moving_thing.Move(destination, M.dir /*So that it's dir doesn't change*/)
In response to IainPeregrine
Ah alright I see now thank you very much for your help!