Godot Version
Godot $
Hello!
I am very new to the whole game developpement scene, i have a problem with this code right here, i want my enemy character to receive damages when it detects a signal from the “hitArea” of my player character, and with some researches, i managed to build a script that i think shoudl work on paper, but it doesn’t. And i can not find how to solve this. I attached the signal to the hurtBox of my enemy Character. If someone could give me a clue i would be forever grateful. Here is the code of my enemy :
extends CharacterBody3D
@onready var navAgent = $NavigationAgent3D
var SPEED = 3.0
var gravity = ProjectSettings.get_setting(“physics/3d/default_gravity”)
var enemyHealth = 100
func _physics_process(delta):
if not is_on_floor():
velocity.y -= gravity * delta
var currentLocation = global_transform.origin
var nextLocation = navAgent.get_next_path_position()
var newVelocity = (nextLocation - currentLocation).normalized() * SPEED
velocity = newVelocity
move_and_slide()
func updateTargetLocation(target_location):
navAgent.set_target_position(target_location)
######RECEIVE DAMAGE########
func _on_hurt_box_body_shape_entered(playerHitArea):
var Player = get_node(“/root/Player/playerHitArea”)
if Player:
var playerDamage = Player.playerDamage
enemyHealth -= playerDamage
print(“Enemy received damage: %d, Remaining health: %d” % [playerDamage, enemyHealth]) # Print for debugging
else:
print(“Player node not found”)