Make my character block

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By checharor

I’ve created a Health system for my Character, and it’s working like a charm, but now i want to make it block, this ishow i’m doing it:
this is the hp variable:

var hp = 10
var blocking = false

and this is how it detects the collitions:

func _physics_process(_delta):

if get_slide_count() >  0:
			for i in range(get_slide_count()): 
				if "Enemy" in get_slide_collision(i).collider.name:
					dead() #Aplica la función dead()

func dead():
	hp = hp -1 #Igual que hp -= 1
	if hp <= 0:
		is_dead = true
		velocity = Vector2(0, 0)
		$AnimatedSprite.play("Die")
		$CollisionShape2D.set_deferred("disabled",true)
		$Timer.start()

I’ve been trying to make hp = hp if blocking is true and try with hp += 1 and when i press the key that makes block = true it works, but when release it the enemy doesn’t meke damage any more, like the dead function is not applying anymore

Does any one know hoy can i make it work?

Thnx

:bust_in_silhouette: Reply From: jtarallo

Hi, you probably are not setting the blocking variable to false when the player releases the block button, and also your dead() function should look something like this:

func dead():
    if !blocking: 
        hp -= 1
        if hp <= 0:
            is_dead = true
            velocity = Vector2(0, 0)
            $AnimatedSprite.play("Die")
            $CollisionShape2D.set_deferred("disabled",true)
            $Timer.start()

Thnx for your answer, I’ll give it a try and let you know how it goes.

checharor | 2020-06-08 21:36

That did it thnx for your hep dude

checharor | 2020-06-10 04:06

No problem man, good luck with your game!

jtarallo | 2020-06-10 04:57