Our first animation will make the enemy flash bright white when hit
Duplicate the MeshInstance3D
Rename it to DamageHighlight
Add a new StandardMaterial3D
Click on the StandardMaterial3D to expand
In the Transparency property
This ensures the material always appears
in front of other materials
Set the Shading Mode to Unshaded
This ensures there are now shadows
The Enemy capsule now appears bright white
Add an AnimationPlayer node as a child of Enemy
In the Animation Panel add a new Animation and call it TakeDamage
Select the DamageHighlight Node
Find the Visibily property
Click the key next to Visible
Change the duration of the animation to 0.1s
With the timeline at 0.1s
Set the DamageHighlight visible property to false
Click the key next to the visible property again
Your timeline now looks like this
The default state of the DamageHighlight
Select the RESET animation
Uncheck visible in the value property
Now check the timeline for the RESET track
To play this animation in code
Add an onready variable for the AnimationPlayer
In the current health set variable
check if the health is going down
play the TakeDamage animation
Add a recoil animation for the turret
In the Turret scene add a AnimationPlayer as a child
Add a new Animation and call it recoil and set the duration to 0.3s
Find the Transform property
Hit the Key to add a track
Also create the RESET track
Move the timeline to 0.3s
In the Transform property of TurretTop
Switch to the RESET animation
Click on the keyframe at 0.0s
Change the Z value to 0.0m
Add an onready var for the animation player
Test the game - you should notice a satisfying recoil animation when the turret fires