• Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Legacy GM Knockback

J

JustNoa_

Guest
Hi. I have knockback for the player and the enemies in my game, but If the enemy attacks the player, he gets knockback but after that he is staying sliding away very slow. Any solutions?
 

NicoDT

Member
Hi. I have knockback for the player and the enemies in my game, but If the enemy attacks the player, he gets knockback but after that he is staying sliding away very slow. Any solutions?
Please post your code, o we won´t know how to help you.
 
J

JustNoa_

Guest
code for doing damage and knockback to the player:

///Damage the player
if (state != scr_enemy_stall_state) {
var dir = point_direction(other.x, other.y, x, y);
var xdir = lengthdir_x(1, dir);
var ydir = lengthdir_y(1, dir);
var damage = instance_create(other.x+xdir, other.y+ydir, obj_damage);
damage.creator = id;
damage.knockback = 1;
state = scr_enemy_stall_state;
alarm[1] = room_speed;

}
 

NicoDT

Member
code for doing damage and knockback to the player:

///Damage the player
if (state != scr_enemy_stall_state) {
var dir = point_direction(other.x, other.y, x, y);
var xdir = lengthdir_x(1, dir);
var ydir = lengthdir_y(1, dir);
var damage = instance_create(other.x+xdir, other.y+ydir, obj_damage);
damage.creator = id;
damage.knockback = 1;
state = scr_enemy_stall_state;
alarm[1] = room_speed;

}
In that code there´s no knockback movement (not adding speed to the player), I need to see that part. Also, when is it supposed to stop? When the alarm[1] event runs?
If you want the player to stop make sure the speed (or hspeed or vspeed) is 0
 
J

JustNoa_

Guest
I don't know where I coded the knockback, but I have recorded a video, maybe that helps?
 
No, that doesn't help, lol. Stop copying and pasting code into your projects, and start actually learning how the code you're using works. :p

You: "Can you fix my car? It won't start."

Mechanic: "Sure, probably. Bring it to my shop and I'll take a look."

You:"I can't. I don't know where my car is. How about I show you a picture of my car instead? You can fix it then, right?"

Mechanic: "..."
 
Last edited:
J

JustNoa_

Guest
@RichHopelessComposer I'm not copying code, I'm following a tutorial serie on youtube.
Btw. found the code for knockback :D

var dir = point_direction(x, y, other.x, other.y);
var xforce = lengthdir_x (knockback, dir);
var yforce = lengthdir_y (knockback, dir);
with (other) {
physics_apply_impulse(x, y, xforce, yforce);
}
 
Yes, you're copying code from a tutorial. That's why you don't understand how it works or why it's broken. You should skim through the manual and work your way through the tutorials that come packaged with GM, making sure you understand how all the code works in each one before moving onto the next one.
 

NicoDT

Member
@RichHopelessComposer I'm not copying code, I'm following a tutorial serie on youtube.
Btw. found the code for knockback :D

var dir = point_direction(x, y, other.x, other.y);
var xforce = lengthdir_x (knockback, dir);
var yforce = lengthdir_y (knockback, dir);
with (other) {
physics_apply_impulse(x, y, xforce, yforce);
}
Don't use physics. Check this tutorial and try to understand it.

It's important that if you have a problem, at least understant which pieces of codes may be related. If you need help, you have to provide as much information as you can, or we won't be able to help you.
I'd recommend you to check all (or most) of Shaun's tutorials, once you understand them (they are pretty easy to understand, so don't worry) you will be able to solve this kind of problems by yourself.
https://www.youtube.com/user/999Greyfox
 
Top