GMLscripts.com

Discuss and collaborate on GML scripts
Invert

You are not logged in.

#1 2020-09-24 03:57:33

KMK
Member
Registered: 2020-09-24
Posts: 1

top down enemy knockback problem

I am new to this coding thing and I couldn't find a proper knockback coding online so I came up with this "fake knockback" using  [enemy.x - (player.x - enemy.x), enemy.y - (player.y - enemy.y)] to calculate the "inversed" coordinate relative to the enemy and the player, and make it pathfind to that new coordinate to make it looks like knockback.

So far it moves like actual knockback. However, due to it actually being pathfinding in disguise, the sprite keeps turning around toward the new coordinate and turning back to face the player. I couldn't find a way to stop the spinning when the bullet hits so here I am asking for help.

object_enemy:
under create:
state = state.chase;
myPath = path_add();
spd = 2;


under step
var tx, ty;
tx = player.x; ty = player.y;


switch(state)
{
case state.chase:
{
mp_potential_path(myPath, tx, ty, 4, 6, false);
path_start(myPath, spd, path_action_stop, true);
image_angle = direction;
alarm[0] = 30;
if place_meeting(x, y, bullet) state=state.hit;
}
break;

case state.hit:
{
mp_potential_path(myPath, x - (tx - x), y - (ty - y), 1, 1, false);
path_start(myPath, spd +5, path_action_stop, true);
if (!place_meeting(x, y, bullet)) state=state.chase;   
}
}

Last edited by KMK (2020-09-24 04:06:57)

Offline

Board footer

Powered by FluxBB