bull and bear flashing red when take damage
This commit is contained in:
@@ -81,6 +81,8 @@ var _charge_dust_ramp: Gradient = null
|
||||
|
||||
const RigidSkin = preload("res://rigid_skin.gd")
|
||||
|
||||
var _hit_flash_tween: Tween
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
add_to_group(&"player")
|
||||
@@ -1090,6 +1092,7 @@ func take_sword_hit(cause: String = "", hit_pos: Vector3 = Vector3.ZERO) -> void
|
||||
if _dead or _hit_iframes > 0.0:
|
||||
return
|
||||
_hp -= 1
|
||||
_hit_flash()
|
||||
_hit_iframes = DP.f("bull_hit_iframes")
|
||||
health_changed.emit(_hp, _max_hp)
|
||||
hit_taken.emit(cause)
|
||||
@@ -1150,3 +1153,36 @@ func _spawn_blood(hit_pos: Vector3) -> void:
|
||||
p.global_position = hit_pos
|
||||
p.restart()
|
||||
_free_after(p, 1.5)
|
||||
|
||||
|
||||
#hit flashing
|
||||
func _hit_flash() -> void:
|
||||
var meshes := find_children("*", "MeshInstance3D", true, false)
|
||||
|
||||
for node in meshes:
|
||||
var mesh := node as MeshInstance3D
|
||||
if mesh:
|
||||
mesh.material_overlay = _make_hit_overlay()
|
||||
|
||||
if _hit_flash_tween:
|
||||
_hit_flash_tween.kill()
|
||||
|
||||
_hit_flash_tween = create_tween()
|
||||
_hit_flash_tween.tween_interval(0.08)
|
||||
_hit_flash_tween.tween_callback(_clear_hit_flash)
|
||||
|
||||
|
||||
func _make_hit_overlay() -> StandardMaterial3D:
|
||||
var mat := StandardMaterial3D.new()
|
||||
mat.shading_mode = BaseMaterial3D.SHADING_MODE_UNSHADED
|
||||
mat.albedo_color = Color(1.0, 0.03, 0.03, 1.0)
|
||||
return mat
|
||||
|
||||
|
||||
func _clear_hit_flash() -> void:
|
||||
var meshes := find_children("*", "MeshInstance3D", true, false)
|
||||
|
||||
for node in meshes:
|
||||
var mesh := node as MeshInstance3D
|
||||
if mesh:
|
||||
mesh.material_overlay = null
|
||||
|
||||
Reference in New Issue
Block a user