Discuss and collaborate on GML scripts

You are not logged in.

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

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.

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

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

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;

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));   

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


Board footer

Powered by FluxBB