J
joshua huxley
Guest
I need help, does anyone know a good knockback script for GM2?
a top down action rpgThis is pretty vague. We need to know what you're already working with. Is it a platformer? Top down? What movement basis are you using?
(Basically show code xd)
kb = 5;
if(place_meeting(x,y,oObjectThatWillKnockTheObjectBack)){
oObjectThatIsGettingKnockedBack.len = -kb;
}
dir=point_direction(0,0,xaxis,yaxis);
if(xaxis=0 && yaxis=0){
len=0;
}else{
if(len < 0){
len += 0.2;
}else{
len=wsp;
}
}
hsp=lengthdir_x(len,dir);
vsp=lengthdir_y(len,dir);
I tried to use your code, but all it did was invert my player's movementNot entirely sure what you mean by 'knockback' either, but at any point with the changes I made to your code below if the variable 'len' is set to a negative number it will kick backwards.
We can set the object into knockback by setting the 'len' variable to something negative.
For example:
But to not have it immediately reset the speed while negative we need to make it incrementally remove negative speed. You can adjust the '0.2' to be whatever you want depending on how quickly you want the player to recover from it.Code:kb = 5; if(place_meeting(x,y,oObjectThatWillKnockTheObjectBack)){ oObjectThatIsGettingKnockedBack.len = -kb; }
Code:dir=point_direction(0,0,xaxis,yaxis); if(xaxis=0 && yaxis=0){ len=0; }else{ if(len < 0){ len += 0.2; }else{ len=wsp; } } hsp=lengthdir_x(len,dir); vsp=lengthdir_y(len,dir);
if(len < 0){
len += 0.2;
}else{
len=wsp;
}
I found out the problem, it only works while the player is movingdid you add this part?:
With this the movement will be reset after a short deceleration process. Or in other terms, knockback.Code:if(len < 0){ len += 0.2; }else{ len=wsp; }