Skip to main content

On Sale: GamesAssetsToolsTabletopComics
Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Enemy Knockback System (TOP DOWN) GameMaker Studio

A topic by Golly G created Mar 19, 2020 Views: 737
Viewing posts 1 to 1

So I've been working for a while on an enemy knockback system that I just can't seem to figure out. Here's my code:

obj_lifeform (Create Event)

///Variables
maxspd = 5;
vspd = 0;
hspd = 0;
dacc = .5;
acc = .5;
knockback = 1;
knockback_spd = 0;
state = "idle";
entity = "enemy";

obj_lifeform (Collision Event with obj_lifeform)

///Run knockback
dir = point_direction(x, y, other.x, other.y);
other.state = "knockback";
other.knockback_spd = knockback;

scr_knockback

///scr_knockback
x += lengthdir_x(knockback_spd, dir);
y += lengthdir_y(knockback_spd, dir);
alarm[0] = room_speed * 2;

if (knockback_spd <= 0)
{
state = "idle";
}

Alarm[0]

///Decrease knockback
knockback_spd -= .2;


Thank you to anyone who can help!