|Attention||Topic was automatically imported from the old Question2Answer platform.|
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): _set_health(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) enemies[enIndex].get_child(1).get_child(0).play("enemy_hit")
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?