ID:139335
 
Code:
mob
var/canMove = 1

// This method will control whether or not we can move around.
Move()
if (canMove)
..()
// Note that in this method we will move the enemy by pixels. That way
// we don't get a choppy push animation. You can call this method
// Rasengan or something cool like that (I just call it the PushEnemy function.
// Use your imagination though!
// mob/enemy/e is the enemy in question
// tileOffset is the amount of tiles you want to push the enemy
// pixelOffset is the amount of pixels you want to move the enemy by to reach
// its tile goal.
mob
proc/PushEnemy(mob/Piccolo/e, tileOffset, pixelOffset)
var/static/step = 0 // How far we have moved (not in pixels).
var/static/pixel_step = 0 // How far we have moved in pixels.
e.canMove = 0 // We don't want the enemy to move while their being pushed.

pixel_step += pixelOffset // Update the amount of pixel movement.

// Here you should check the tile offset. If we only want to move the player
// by 1 tile then this is pretty pointless. If we want to move the player
// more than 1 tile, then we'll have something really interesting going on.
if (tileOffset == 1)
step++
else if(32 - pixel_step <= 0)
step++
pixel_step = 0

// Here we'll just wait 1/10 of a second before we call the function again. Also,
// we base the movement of the enemy from our direction.
spawn(1)
if (step != tileOffset)
switch (src.dir)
if (NORTH)
e.pixel_y += pixelOffset
if (SOUTH)
e.pixel_y -= pixelOffset
if (EAST)
e.pixel_x += pixelOffset
if (WEST)
e.pixel_x -= pixelOffset
PushEnemy(e, tileOffset, pixelOffset)
else
switch (src.dir)
if (NORTH)
e.loc = locate(e.loc.x, e.loc.y+step, 1)
if (SOUTH)
e.loc = locate(e.loc.x, e.loc.y-step, 1)
if (EAST)
e.loc = locate(e.loc.x+step, e.loc.y, 1)
if (WEST)
e.loc = locate(e.loc.x-step, e.loc.y, 1)

// We want to reset these variables. The pixel_x and pixel_y distort the
// location of the character and we want to make sure we set them back to 0.
// Furthermore we want to set step and pixel_step back to 0 since they are
// static variables.
e.canMove = 1
e.pixel_x = 0
e.pixel_y = 0
step = 0
pixel_step = 0


mob/verb
Rasengan(mob/Piccolo/e in oview(1))
// Here we will move the enemy 2 tiles at a rate of 4 pixels per 1/10 seconds.

src.PushEnemy(e, 5, 10)


Problem description:
Ok so Im using a basic demo code for a knockback system and what i noticed is once you knock back the person if you move and change direction the person being pushed shifts and moves that direction.Due to the spawn initiating the first push which is based off the users direction.

So how do I fix it so I hit the npc or w/e and knock em back and then be able to move around without the person shifting direction I move in while there being pushed.

Example: I push em up then while there being pushed I move down they will then change direction and start to move down instead of the original direction
You should save the player's direction before the spawn(1), and use the saved direction instead of their current direction, like this:
Code:
> mob
> var/canMove = 1
>
> // This method will control whether or not we can move around.
> Move()
> if (canMove)
> ..()
> // Note that in this method we will move the enemy by pixels. That way
> // we don't get a choppy push animation. You can call this method
> // Rasengan or something cool like that (I just call it the PushEnemy function.
> // Use your imagination though!
> // mob/enemy/e is the enemy in question
> // tileOffset is the amount of tiles you want to push the enemy
> // pixelOffset is the amount of pixels you want to move the enemy by to reach
> // its tile goal.
> mob
> proc/PushEnemy(mob/Piccolo/e, tileOffset, pixelOffset)
> var/static/step = 0 // How far we have moved (not in pixels).
> var/static/pixel_step = 0 // How far we have moved in pixels.
> e.canMove = 0 // We don't want the enemy to move while their being pushed.
>
> pixel_step += pixelOffset // Update the amount of pixel movement.
>
> // Here you should check the tile offset. If we only want to move the player
> // by 1 tile then this is pretty pointless. If we want to move the player
> // more than 1 tile, then we'll have something really interesting going on.
> if (tileOffset == 1)
> step++
> else if(32 - pixel_step <= 0)
> step++
> pixel_step = 0
>
> // Here we'll just wait 1/10 of a second before we call the function again. Also,
> // we base the movement of the enemy from our direction.
> var/movedir = src.dir // this line added
> spawn(1)
> if (step != tileOffset)
> switch (movedir) // this line changed
> if (NORTH)
> e.pixel_y += pixelOffset
> if (SOUTH)
> e.pixel_y -= pixelOffset
> if (EAST)
> e.pixel_x += pixelOffset
> if (WEST)
> e.pixel_x -= pixelOffset
> PushEnemy(e, tileOffset, pixelOffset)
> else
> switch (movedir) // this line changed
> if (NORTH)
> e.loc = locate(e.loc.x, e.loc.y+step, 1)
> if (SOUTH)
> e.loc = locate(e.loc.x, e.loc.y-step, 1)
> if (EAST)
> e.loc = locate(e.loc.x+step, e.loc.y, 1)
> if (WEST)
> e.loc = locate(e.loc.x-step, e.loc.y, 1)
>
> // We want to reset these variables. The pixel_x and pixel_y distort the
> // location of the character and we want to make sure we set them back to 0.
> // Furthermore we want to set step and pixel_step back to 0 since they are
> // static variables.
> e.canMove = 1
> e.pixel_x = 0
> e.pixel_y = 0
> step = 0
> pixel_step = 0
>
>
> mob/verb
> Rasengan(mob/Piccolo/e in oview(1))
> // Here we will move the enemy 2 tiles at a rate of 4 pixels per 1/10 seconds.
>
> src.PushEnemy(e, 5, 10)
>
>