my attack funtion isnt working my coad

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

const type = "Player"

signal health_updated(health)
signal killed()

const UP =  Vector2(0,-1)
const GRAVITY = 30
const MAXFALLSPEED = 5500
const MAXSPEED = 800
const jumpforce = 1675
const accel = 20

export var max_health = 10
onready var health = max_health setget _set_health
onready var invulnerability_timer = $invulnerabilityTimer

var motion = Vector2()
var facing_right = true
var isAttacking = false;
var is_dead = false

func _physics_process(delta):
	if is_dead == false:
		motion.y += GRAVITY
		if motion.y > MAXFALLSPEED:
			motion.y = MAXFALLSPEED
		if facing_right == true:
			$Sprite.scale.x = 10
			$Sprite.scale.x = -10
		motion.x = clamp(motion.x,-MAXSPEED,MAXSPEED)
		if Input.is_action_pressed("right") && isAttacking == false:
			motion.x += accel
			facing_right = true
			get_node("attackarea").position = Vector2(25, 1)
		elif Input.is_action_pressed("left") && isAttacking == false:
			motion.x -= accel
			get_node("attackarea").position = Vector2(-225, 1)
			facing_right = false
			motion.x = 0;
			if isAttacking == false:
		if is_on_floor():
			if Input.is_action_just_pressed("jump"):
				motion.y = -jumpforce
		if !is_on_floor():
			if motion.y < 0:
			elif motion.y > 0:
		if Input.is_action_just_pressed("attack"):
			isAttacking = true;
			$attackarea/attackcolision.disabled = false;
		motion = move_and_slide(motion, UP * delta)
func _set_health(value):
	if value > 0:
		emit_signal("health_updated", value)
	var prev_health = health
	health = clamp(value, 1, max_health)
	if health != prev_health:
		emit_signal("health_updated", health)	
func damage(amount):
	if invulnerability_timer.is_stopped():
		_set_health(health - amount)

func kill():

func dead():
	is_dead = true
	Vector2(0, 0)
func heal(amount):
	if is_dead == false:
		health += amount
		health = min(health, max_health)
		emit_signal("health_updated", health)
		print("%s got healed by %s points. Health: %s/%s" % [get_name(), amount, health, max_health])
func _on_invulnerabilityTimer_timeout():

func _on_AnimationPlayer_animation_finished(attack):
	$attackarea/attackcolision.disabled = true;
	isAttacking = false;

func _on_Timer_timeout():

func _on_Area2D_body_entered(body):

“Isn’t working” is way too vague for anyone to help. Please, help us to help you. For starters:

  • Describe the problem in detail
  • How do you expect it to work?
  • What exactly isn’t working as expected?
  • Do you get any errors? If so, please past the entire error message.
  • When posting code, format it for the forum (using the { } button in the editors toolbar). Otherwise, it’s nearly impossible to read.

Just dumping a wall of unformatted code in a post and saying “this isn’t working” won’t get you to a solution. If you expect someone to spend the (likely considerable) time it’ll take to assist you, at least take the time provide the necessary details.

jgodfrey | 2022-07-29 16:59

I agree with Jgodfrey

godot_dev_ | 2022-07-29 17:05

-my problem is there are invulnerability and damage animations when I take damage I want them to activate.
-the animation isn’t activating
-no I don’t have any errors
-thanks for your advice i didn’t know that

hiruy | 2022-07-29 17:05

if there is some thing you want to know pls tell me

hiruy | 2022-07-29 17:07

Please edit your post and format the code for the forum. To do that…

  • Edit the original post
  • Select the code
  • Press the { } button in the forum’s mini-toolbar.
  • Look at the Preview section (below the forum edit box) to verify the code’s format
  • Save the edited message.

jgodfrey | 2022-07-29 17:13

thanks this helped

hiruy | 2022-07-29 17:16

Maybe its about this code

func _on_AnimationPlayer_animation_finished(attack):

it Should be like

func _on_AnimationPlayer_animation_finished(anim_name):

And Whats The Problem BTW?

Beatrix | 2022-07-29 17:44


hiruy | 2022-07-29 17:51

but do you take damage or the you take damage but animation is not playing?

Beatrix | 2022-07-29 17:55

I take damage but the animation isnt playing

hiruy | 2022-07-29 17:56

Well You Start A Timer On The Damage Function


when that timer end this function runs

func _on_invulnerabilityTimer_timeout():

so the animation will change to rest right?

Beatrix | 2022-07-29 18:01

yes i want it to change to rest

hiruy | 2022-07-29 18:03

Here Change The

func _on_AnimationPlayer_animation_finished(attack):


func _on_AnimationPlayer_animation_finished(anim_name):
  if anim_name == "attack":
    $attackarea/attackcolision.disabled = true;
    isAttacking = false;
  if anim_name == "damage":

remove this

    if invulnerability_timer.is_stopped():

Beatrix | 2022-07-29 18:08

excuse me this didn’t work if you want more info about the animation it is an animation that flashes and turns the character red when token damage the rest animation just turns things back to normal it something has gone wrong

hiruy | 2022-07-29 18:18

jus t upload the project ill try my best to fix it

Beatrix | 2022-07-29 18:23

ok here you go GitHub - hiruy56/game: this is my 2d game

hiruy | 2022-07-29 18:33

great give me an 10-30 minute

Beatrix | 2022-07-29 18:35

:bust_in_silhouette: Reply From: Beatrix

here fixed

its because of the walking animation
i just duplicated the animation

*added font

gonna sleep its 3:17 AM here at the Philippines so bye and thx for patience

Beatrix | 2022-07-29 19:18