0 votes

Hello guys so what I want to ask is that I made a scene called Enemy Scene which consists of my basic enemy for my game. Earlier I used CTRL + D to make copies of my enemy and then used them in my Main Scene but recently I added a life bar on top of my enemy. Now when I use simple copying, killing one enemy kills all other enemies too. How can I fix this ?

in Engine by (416 points)

1 Answer

+1 vote

That shouldn't happen. Where is the health variable stored? If it is stored in a global script, then the variable is linked to all the enemies. If it it stored in each individual one (stored in a script attached to the enemy) then they should die individually. Perhaps you have a problem with collision detection. The question needs more context. How do you kill the enemies? Where is the Health variable stored?

by (83 points)

This is my enemy script :

var direction=1

var is_dead=false
export(int) var hp=10

func _ready() -> void:
    pass # Replace with function body.

func dead():
    if hp<=0:

func _physics_process(delta):
    if is_dead==false:
        if direction == 1:
        velocity=move_and_slide(velocity, FLOOR)

    if is_on_wall():

    if $RayCast2D.is_colliding()==false:

    if get_slide_count()>0:
            for i in range(get_slide_count()):
                if "Player" in get_slide_collision(i).collider.name:

func _on_Timer_timeout() -> void:

and this is my script for Progress Bar which appears on top of my Enemy :

extends ProgressBar

func _ready():

func _physics_process(delta):

All this is fine but I want to make multiple copies of my same enemy for my game stage ! Simply copying over the Enemy node isn't giving me desired results as the enemies do appear and can be destroyed too but their life bar doesn't change and stays full except the one enemy from which all others were copied. That's probably because the copies have numbers added to their names like enemy1,enemy2 and so on and I must change the name in progress bar script. But If I change the name of node there than still the issue prevails because now let's say that enemy1 is working as desired but enemy is showing full life bar. Is there any way I can make copies of enemy and make the life bar interact with each of them separately and not simultaneously

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.