bull and bear flashing red when take damage
This commit is contained in:
@@ -59,6 +59,10 @@ var _anim_smash: StringName = &"" # SMASH_HIT — overhead smash
|
||||
var _anim_leap: StringName = &"" # JUMP_SMASH — leap slam
|
||||
var _anim_death: StringName = &"" # DEATH — death
|
||||
|
||||
#take hit flashing
|
||||
var _hit_flash_active := false
|
||||
var _hit_flash_tween: Tween
|
||||
|
||||
const _ACCEL_FACTOR: float = 9.0
|
||||
# Hard deceleration for planted states (wind-up / recovery / neutral settle) so the bear
|
||||
# never coasts across the ground with a stationary pose playing (no foot-sliding).
|
||||
@@ -117,6 +121,45 @@ func _ready() -> void:
|
||||
_setup_claws()
|
||||
_enter_neutral()
|
||||
|
||||
#take hit flashing
|
||||
func _hit_flash() -> void:
|
||||
if _mesh == null:
|
||||
return
|
||||
|
||||
if _hit_flash_tween:
|
||||
_hit_flash_tween.kill()
|
||||
|
||||
_hit_flash_active = true
|
||||
|
||||
# Make the bear red
|
||||
for child in _mesh.find_children("*", "MeshInstance3D", true, false):
|
||||
var mesh := child as MeshInstance3D
|
||||
if mesh:
|
||||
mesh.material_overlay = _make_hit_overlay()
|
||||
|
||||
# Flash for 0.1 sec, then remove
|
||||
_hit_flash_tween = create_tween()
|
||||
_hit_flash_tween.tween_interval(0.10)
|
||||
_hit_flash_tween.tween_callback(_clear_hit_flash)
|
||||
|
||||
func _make_hit_overlay() -> StandardMaterial3D:
|
||||
var mat := StandardMaterial3D.new()
|
||||
mat.albedo_color = Color(1.0, 0.05, 0.05, 1.0)
|
||||
mat.shading_mode = BaseMaterial3D.SHADING_MODE_UNSHADED
|
||||
return mat
|
||||
|
||||
func _clear_hit_flash() -> void:
|
||||
if _mesh == null:
|
||||
return
|
||||
|
||||
for child in _mesh.find_children("*", "MeshInstance3D", true, false):
|
||||
var mesh := child as MeshInstance3D
|
||||
if mesh:
|
||||
mesh.material_overlay = null
|
||||
|
||||
_hit_flash_active = false
|
||||
|
||||
|
||||
|
||||
# Bind a claw-slash emitter to each paw bone (hand_l / hand_r) via a BoneAttachment3D, so
|
||||
# a burst fired on a swipe hit erupts from that paw wherever the animation has it.
|
||||
@@ -698,6 +741,7 @@ func _take_hit(hit_dir: Vector3, strength: float) -> void:
|
||||
if _state == State.DEAD:
|
||||
return
|
||||
_hp -= 1
|
||||
_hit_flash()
|
||||
health_changed.emit(_hp, int(DP.f("bear_max_hp")))
|
||||
hit_dir.y = 0.0
|
||||
hit_dir = hit_dir.normalized()
|
||||
|
||||
Reference in New Issue
Block a user