ID:1708403
 
(See the best response by Gokussj99.)
I want to add a knockback effect for players getting hit, but so far its inconsistent and isn't clean. You can clearly see the delay in the steps because the mob doesn't fluidly move when being knocked back.

mob/proc
KB(mob/M, var/Damage)
var/KB = M.maxhp / Damage
var/d = src.dir
if(KB > 100)
else if(KB > 80)
Knockback(M,1,d)
else if(KB > 50)
Knockback(M,2,d)
else if(KB > 30)
Knockback(M,3,d)
else if(KB > 10)
Knockback(M,4,d)
else if(KB > 1)
Knockback(M,6,d)

Knockback(mob/m, var/n, var/d)
var/i
for(i=n, i > 0, i--)
step(m,d)
sleep(2)


Its most likely because of the sleep proc, but without it the step proc won't execute more than once. Is there a way to make it more fluid?
Best response
I think most likely it is being executed more than once however you're not really defining step's speed so it may seem like you're not moving at all try adding like 10 to step or something after d so m,d,10 and also yes remove the sleep adjust the step speed as needed.

    proc
knockBack(var/mob/m=null, var/amount=5 as num, var/dir=WEST, var/speed=m.step_size as num){
set waitfor = 0;

for(var/i=amount,i>0,i--){
step(m,dir,speed);
}
}
Setting the speed for step doesn't work sadly. I've tried from 1 to 1000 and it just moves the exact same every time. Maybe its because I'm using pixel movement. I also don't want to use walk because then I'd have to stop walk after a few seconds and it'll continue to run in the background. Walk away will works, but if the attacker follows after whoever they knocked back they'll just get knocked farther since the reference point is the attacker.
In response to Gluscap
Gluscap wrote:
Setting the speed for step doesn't work sadly. I've tried from 1 to 1000 and it just moves the exact same every time. Maybe its because I'm using pixel movement. I also don't want to use walk because then I'd have to stop walk after a few seconds and it'll continue to run in the background. Walk away will works, but if the attacker follows after whoever they knocked back they'll just get knocked farther since the reference point is the attacker.

I tested this using pixel movement it worked fine.

Also if i'm not mistaken step uses movement in pixels for speed.

EDIT: Confirmed.

    step proc

See also:
get_step proc
walk proc
step_size var (movable atom)

Format:
step(Ref,Dir,Speed=0)

Returns:
1 on success; 0 otherwise

Args:
Ref: A mob or obj.
Dir: One of NORTH, SOUTH, EAST, WEST, NORTHEAST, NORTHWEST, SOUTHEAST, SOUTHWEST.
Speed: Speed to move, in pixels. 0 uses Ref.step_size.

Move Ref in the direction Dir.
In response to Gluscap
Are you maybe using a move delay, like you would for tile movement, but which is completely counterintuitive for pixel movement? That would prevent moving more than once within a certain amount of time.
Yeah, that was the problem. goku's solution works now, thanks.