0 votes

Hello everyone.

I'm currently very new to Godot and I'm figuring out how to implement basic FPS mechanics. So far I've added:
- a controller (moving, jumping and dashing)
- a simple shooting mechanic, where a raycast checks whether the collider is an enemy object or not
- enemy AI which currently just chases the player.

I added a quick animation, titled "enemy_hit", to show that the enemy object has been hit. It consists of changing the material (albedo) to a more intense shade of red for 1/3 of a second. The problem is that every instance of that object plays this animation simultaneously.

In my enemy scene, called "EnemyTarget", I have a function which runs whenever there's a collision between the object and the player's raycast when firing:

signal health_drained 
func hit(damage_output):
    emit_signal("health_drained", self)
    if (health == 0):
        emit_signal("health_depleted", name)

The health_drained signal is sent to the main scene. I store the enemy nodes in an array (and I know it's probably not optimal, but it's a temporary solution), so when the signal is emitted, I search for the index of the target node and play the animation afterwards. the code is as follows:

func _on_enemy_hit(enemyObj):
    var enIndex = enemies.find(enemyObj, 0)

So... any ideas? I have no idea how to make it so that only one instance plays the animation. Maybe it has to do something with the material?

Godot version 3.5
in Engine by (23 points)

1 Answer

+1 vote
Best answer

Yes, it is only about the material.
Get to material in editor, find resource property, open it, and in its submenu tag local_to_the_scene

By the way, why can't You just :

func on_enemy_hit(enemyObj) :

Why would you go all the way to find this object in array ? :)
And why won't enemies handle their own animations ?

by (8,101 points)
selected by

Thank you for the answer!
They originally handled them on their own, but i thought that finding the specific collider in the array would fix this problem. I'll put that command back in their own script.

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 [email protected] with your username.