Why Signals are not working?

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

Hello, im trying to make a simple auto-combat so if it gets close to something, play the attack animation

I use 2 Area2D with a collisionshape2D each. and both uses on_body_entered()

So the Area2Dl that makes the character move to the target works perfect, but when the target gets into the attack area, no animation displays, also put some prints() to debug and the dont respond either.

i dont knwo what I’m missing.

code here:

extends KinematicBody2D

export var speed = 200

var target = position
var motion = Vector2()
var is_attacking = false

func _input(event):
if event.is_action_pressed(“right_click”):
target = get_global_mouse_position()

func _physics_process(delta):
print(is_attacking)
attack()
get_motion()

func get_motion():
motion = (target - position).normalized() * speed

if (target - position).length() > 5:
	if motion.x > 0:
		$AnimatedSprite.flip_h = false
	elif motion.x < 0:
		$AnimatedSprite.flip_h = true
	motion = move_and_slide(motion)
	$AnimatedSprite.play("Walk")
else:
	$AnimatedSprite.play("Idle")

func _on_Aggro_body_shape_entered(body_id, body, body_shape, area_shape):
target = body.position

func _on_attk_area_body_shape_entered(body_id, body, body_shape, area_shape):
is_attacking = true
$attk_cooldown.start()
print($attk_cooldown.get_time_left())

func _on_attk_cooldown_timeout():

print("Attaking")

func attack():
if is_attacking:
print(“Attaking”)
$AnimatedSprite.play(“Attack”)
else:
pass

sorry bout the code, dont know why it doesnt copy-paste properlly…
:frowning:

Thank you guys

Did you connect the signals using the Node interface of Godot? If you just manually wrote the functions, they won’t work.

selamba | 2019-12-01 22:02

:bust_in_silhouette: Reply From: ItsYoBoi

I personally didnt use signals to get my player to move. Maybe my player script will be helpful. You just need to adjust the character movement and keys in the project settings.

extends KinematicBody2D

const SPEED = 250
const GRAVITY = 10
const JUMP_POWER = -500
const FLOOR = Vector2(0, -1)


var velocity = Vector2()

var jump = false
var jump_speed = 10
var on_ground = false
var can_move = true
var is_attacking = false

func _physics_process(delta):
	if Input.is_action_pressed("forward"):
		if is_attacking == false || is_on_floor() == false:
			velocity.x = SPEED
			if is_attacking == false:
				$AnimatedSprite.play("run")
				$AnimatedSprite.flip_h = false
				if sign($Position2D.position.x) == -1:
					$Position2D.position.x *= -1
	elif Input.is_action_pressed("backward"):
		if is_attacking == false || is_on_floor() == false:
			velocity.x = -SPEED
			if is_attacking == false:
				$AnimatedSprite.play("run")
				$AnimatedSprite.flip_h = true
				if sign($Position2D.position.x) == 1:
					$Position2D.position.x *= -1
	else:
		velocity.x = 0
		if on_ground == true && is_attacking == false:
			$AnimatedSprite.play("idle")
	
	if Input.is_action_pressed("jump"):
		if is_attacking == false:
			if on_ground == true:
				velocity.y = JUMP_POWER
				$AnimatedSprite.play("jump")
				on_ground == false