var hitstun = 0
var velocity = Vector2.ZERO
var knockback= Vector2.ZERO
var knockbackSpeed = 110
onready var hurtbox = $Hurtbox
func _physics_process(delta):
move()
if hitstun > 0:
hitstun -= 1
elif hit_stun == 0 && hurtbox.monitoring == false:
hurtbox.set_deferred("monitoring", true)
func move():
if hitstun == 0:
velocity = move_and_slide(velocity)
else:
knockback= move_and_slide(knockback)
func _on_Hurtbox_area_entered(area):
hitstun = 10
health -= area.damage # I added an export var damage = 1 on the "hitbox"
knockback = global_position - area.global_position
knockback = (knockback.normalized() * knockbackSpeed)
hurtbox.set_deferred("monitoring", false)
create an area2D call it what ever you call the area_entered signal in this case Hurtbox
make it have its own collition layer and a collision shape.
then make the hitbox of whatever attack or enemy collition mask to that layer.
you can also add something like the monitoring stuff to make it so that u cant get hit whilst "stunned/knockbacked" if not wanted just ignore spoilers.
altho not the best way to do "invincibility" but it is an easy way to do it on a comment x)