Attention | Topic was automatically imported from the old Question2Answer platform. | |
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…
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