fix(gameplay): escape pause menu + block placement collision + perf optim render_distance/throttling

This commit is contained in:
Floppyrj45
2026-04-19 17:32:59 +02:00
parent 3fa02492a2
commit 9546fcd96b
8 changed files with 164 additions and 21 deletions

View File

@@ -8,6 +8,7 @@ var _fish_meshes: Array[MeshInstance3D] = []
var _fish_velocities: Array[Vector3] = []
var _time: float = 0.0
var _player: CharacterBody3D = null
var _boid_update_timer: float = 0.0
func _ready() -> void:
_find_player()
@@ -62,6 +63,17 @@ func _process(delta: float) -> void:
if _player == null:
_find_player()
# Throttle boid calculations to 10 Hz
_boid_update_timer += delta
if _boid_update_timer >= 0.1:
_update_boids(_boid_update_timer)
_boid_update_timer = 0.0
# Apply velocities every frame for smooth movement
_apply_velocities(delta)
func _update_boids(dt: float) -> void:
for i: int in range(_fish_meshes.size()):
var fish: MeshInstance3D = _fish_meshes[i]
var vel: Vector3 = _fish_velocities[i]
@@ -91,12 +103,12 @@ func _process(delta: float) -> void:
avg_vel /= float(neighbor_count)
var cohesion_force: Vector3 = (avg_pos - fish.position).normalized() * 0.5
var alignment_force: Vector3 = avg_vel.normalized() * 0.3
vel += (cohesion_force + alignment_force) * delta * 2.0
vel += (cohesion_force + alignment_force) * dt * 2.0
# --- Global cohesion: return to school center ---
var center_offset: Vector3 = fish.position # positions are local to school node
var center_offset: Vector3 = fish.position
if center_offset.length() > school_radius:
vel += -center_offset.normalized() * 1.5 * delta * 4.0
vel += -center_offset.normalized() * 1.5 * dt * 4.0
# --- Player avoidance ---
if is_instance_valid(_player):
@@ -104,7 +116,7 @@ func _process(delta: float) -> void:
var dist_to_player: float = world_fish_pos.distance_to(_player.global_position)
if dist_to_player < 3.0:
var flee: Vector3 = (world_fish_pos - _player.global_position).normalized()
vel += flee * 4.0 * delta * (3.0 - dist_to_player)
vel += flee * 4.0 * dt * (3.0 - dist_to_player)
# Clamp speed
if vel.length() > swim_speed * 1.5:
@@ -113,6 +125,12 @@ func _process(delta: float) -> void:
vel = vel.normalized() * 0.3
_fish_velocities[i] = vel
func _apply_velocities(delta: float) -> void:
for i: int in range(_fish_meshes.size()):
var fish: MeshInstance3D = _fish_meshes[i]
var vel: Vector3 = _fish_velocities[i]
fish.position += vel * delta
# Rotate mesh to face velocity direction