So I followed a tutorial for making a knockback system, the first one that pops up on youtube, fiddled around with it a bunch but made it to work, but when I copy paste an enemy and try to knockback the other enemy it just knockbacks the original instance. I genuinelly have no idea why this happens, there is a comment that has the same exact issue, here is the code:
func punch_knockback():
if knockback == true and is_on_floor():
if facingright != player_dir:
facingright = player_dir
scale.x = -scale.x
if knockback == true:
if facingright == true:
motion.x = 500
elif facingright == false:
motion.x = -500
if knockback == true:
motion.y = -100
if $Sprite/detectwallbounceright.is_colliding() and facingright == true and bouncetimer > 0.1:
motion.x = -60
facingright = false
bouncetimer = 0
scale.x = -1
Global.camera.shake(0.1,0.5)
frameFreeze(0.01, 0.2)
elif $Sprite/detectwallbounceright.is_colliding() and facingright == false and bouncetimer > 0.1:
motion.x = 60
facingright = true
bouncetimer = 0
scale.x = -1
Global.camera.shake(0.1,0.5)
frameFreeze(0.01, 0.2)
motion.x = clamp(motion.x,-knockmaxspeedx,knockmaxspeedx)
if knocktimer > maxknocktime:
knockback = false
here is the code from the player:
for body in $attack.get_overlapping_bodies():
if knockback_wait <= 0 and body.get("NAME") == "enemy" and punchslide == true:
knockback_wait = 50
emit_signal("knockback")
frameFreeze(0.01, 1.0)
Global.camera.shake(0.2,2)
Thank you all in advance