Invalid get index 'damage' (on base: 'Area2D (PlayerDetection.gd)').

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

just help, I am really confused

extends KinematicBody2D

const EnemyDeathEffect = preload(“res://escenas/bateffect.tscn”)

export var ACCELERATION = 300
export var MAX_SPEED = 50
export var FRICTION = 200

enum{
IDLE,
WANDER,
CHASE
}

var velocity = Vector2.ZERO
var state = CHASE
var knockback = Vector2.ZERO
onready var stats = $Stats
onready var playerDetectionZone = $PlayerDetection

func _physics_process(delta):
knockback = knockback.move_toward(Vector2.ZERO, FRICTION * delta)
knockback = move_and_slide(knockback)

match state:
	IDLE:
		velocity = velocity.move_toward(Vector2.ZERO, FRICTION *delta)
		seek_player()
	WANDER:
		pass
	CHASE:
		var player = playerDetectionZone.player
		if player != null:
			var direction = (player.global_position - global_position).normalized()
			var velocity = velocity.move_toward(direction * MAX_SPEED, ACCELERATION * delta)
velocity = move_and_slide(velocity)

func seek_player():
if playerDetectionZone.can_see_player():
state = CHASE

func _on_Hurtbox_area_entered(area):
stats.health -= area.damage
knockback = area.knockback_vector * 100

func _on_Stats_no_health():

queue_free()
var enemyDeathEffect = EnemyDeathEffect.instance()
get_parent().add_child(enemyDeathEffect)
enemyDeathEffect.global_position = global_position
queue_free()

enter code here

Wild guess:

The Area, that entered has no varibale damage. Check your Collisionlayer and -mask. Maybe add:

print(area.name) # just for debugging

before the error occourse, to see if it is the correct Area.

Maybe this can help.

whiteshampoo | 2020-06-11 05:35

:bust_in_silhouette: Reply From: MaaaxiKing

Neither damage nor knockback_vector is an attribute of area. Do you want to do damage in an area or what are you trying to do? If you want to do damage to the player if it enters the area you have to declare and initialize damage first.

I am having this same problem. I am trying to make the enemy chase me if I am a certain distance.

MeatBoi | 2020-09-14 17:26