add shake when buildings take damage

This commit is contained in:
Michael Campbell 2026-02-19 01:14:58 -05:00
parent 53b8cf6118
commit e7366631ad
2 changed files with 20 additions and 0 deletions

View file

@ -3,9 +3,24 @@ extends CollisionObject3D
var health := 10.
@export var shake_noise: FastNoiseLite
var shake_duration := 0.
@onready var initial_mesh_pos: Vector3 = %Mesh.position
func _ready() -> void:
scale.y = randf_range(.5, 1.25)
func _process(delta: float) -> void:
if shake_duration <= 0:
%Mesh.position = initial_mesh_pos
else:
var x := shake_noise.get_noise_1d(shake_duration * 10000)
var y := shake_noise.get_noise_1d(-shake_duration * 10000)
%Mesh.position = initial_mesh_pos + (Vector3(x, 0, y) * 0.75)
shake_duration = move_toward(shake_duration, 0., delta)
func hit(_proj: PlayerProjectile, damage: float) -> bool:
health -= damage
if health <= 0.:
@ -16,5 +31,7 @@ func hit(_proj: PlayerProjectile, damage: float) -> bool:
%Mesh.hide()
%DestroyedMesh.show()
%GPUParticles3D.preprocess = randf()
else:
shake_duration += 0.5
return true

View file

@ -2,6 +2,8 @@
[ext_resource type="Script" uid="uid://bnr37lfj76u7n" path="res://world/building/building.gd" id="1_5j34s"]
[sub_resource type="FastNoiseLite" id="FastNoiseLite_d2kbb"]
[sub_resource type="BoxMesh" id="BoxMesh_rqn35"]
size = Vector3(3, 5, 3)
@ -48,6 +50,7 @@ material = SubResource("StandardMaterial3D_2vvqs")
collision_layer = 5
collision_mask = 0
script = ExtResource("1_5j34s")
shake_noise = SubResource("FastNoiseLite_d2kbb")
[node name="Mesh" type="MeshInstance3D" parent="." unique_id=1919101154]
unique_name_in_owner = true