Add crowd presentation, fix NPC navigation, refresh screenshots
NPC navigation (previously dead in the live game) - Only assign NavigationAgent3D.target_position when it changes: re-assigning every frame invalidated the path, so get_next_path_position() kept returning the current point and avatars never moved. - Follow the first path point that is closer to the destination than the avatars are. Nav points sit on the navmesh plane (y=0) while bodies stand at y~0.5, so the old 3D distance test always looked "already there"; path[0] is also the old start point, so a naive "far enough away" pick steered backwards and oscillated. - Fix fsm.state -> fsm.current_state in the idle-lifetime check. Crowd presentation - Aggressive behavior, visible weapons, and responder arrivals make idle bystanders stop and face the incident for 12 s; someone waiting at the entrance keeps focus. - Panic (mood >= 0.75) walks people away from the door at 2.4 m/s, then they despawn. - Wire reactions to EventBus.crowd_changed: CrowdSystem.apply_event() emits on the bus, not on its own `changed` signal (the first wiring received nothing). - Measured a 16-NPC entrance at ~1.2 ms/frame (824 fps, vsync off), so no LOD/culling. World and HUD - Skyline is now a ring of four alpha-scissored planes at 200 m instead of a single plane; PlaneMesh defaults to horizontal, which is why the backdrop rendered as a band overhead. Larger ground plane, mipmapped texture, scissor threshold 0.5 (0.3 left mip dashes in the sky), lifted albedo so the city is not pure black. - Flashlight aims straight ahead and lights the person/door instead of the ground. - Shorter HUD controls line so it stops overlapping itself. Tests, tooling, docs - Headless suite 98 -> 105 (new test_crowd_presentation.gd, 7 tests). - New smoke_crowd.gd: rubbernecking, panic, and flee-target sanity. - capture_screenshots.gd starts a shift from the venue menu and stages the night set properly; all six README screenshots regenerated. - README, TODO/DONE (crowd section moved), MEMORY updated. Version 0.2.4.
This commit is contained in:
1 parent
f5ad1642b5
commit
71b0b53705
21 files changed
+512
-60
No files matched your search
+105
-6
@@ -17,6 +17,14 @@ var arrived := false
|
||||
var idle_s := 0.0
|
||||
var lifetime_s := 90.0
|
||||
var ephemeral := true
|
||||
## Crowd presentation (PLAN: Public Crowd Reaction). "watch" rubbernecks at the
|
||||
## incident, "flee" clears away from it, "" is normal navigation.
|
||||
var reaction_mode := ""
|
||||
var reaction_point := Vector3.ZERO
|
||||
var _reaction_timer := 0.0
|
||||
const RUBBERNECK_S := 12.0
|
||||
const FLEE_S := 20.0
|
||||
const FLEE_SPEED := 2.4
|
||||
var agent: NavigationAgent3D = null
|
||||
## Set once the nav agent proves it has a path; direct movement is the fallback.
|
||||
var _nav_usable := false
|
||||
@@ -225,10 +233,78 @@ func _add_box_prop(parent: Node3D, size: Vector3, pos: Vector3, color: Color) ->
|
||||
mi.material_override = _material(color)
|
||||
parent.add_child(mi)
|
||||
|
||||
## Rubberneck: idle people stop and turn toward the incident. Returns false when
|
||||
## this NPC is too engaged (walking, being talked to, already leaving) to watch.
|
||||
func start_rubberneck(at: Vector3) -> bool:
|
||||
if not arrived or npc.leave_requested or leave_requested_by_lifetime:
|
||||
return false
|
||||
# Someone actually waiting at the entrance is being dealt with, not a bystander.
|
||||
# Avatars live under the identity SceneRoot, so `position` matches world space
|
||||
# and also works before the node enters the tree (tests).
|
||||
if awaiting_interaction and (position - door_position).length() < 3.0:
|
||||
return false
|
||||
if reaction_mode == "flee":
|
||||
return false
|
||||
reaction_mode = "watch"
|
||||
reaction_point = at
|
||||
_reaction_timer = RUBBERNECK_S
|
||||
velocity = Vector3.ZERO
|
||||
return true
|
||||
|
||||
## Panic: clear away from the incident (usually the door) in a straight line.
|
||||
func start_flee(from: Vector3) -> void:
|
||||
if npc.leave_requested or leave_requested_by_lifetime:
|
||||
return
|
||||
reaction_mode = "flee"
|
||||
reaction_point = from
|
||||
_reaction_timer = FLEE_S
|
||||
var away := global_position - from
|
||||
away.y = 0.0
|
||||
if away.length() < 0.5:
|
||||
away = Vector3(0.0, 0.0, 1.0)
|
||||
target_position = global_position + away.normalized() * 25.0
|
||||
target_position.y = 0.5
|
||||
arrived = false
|
||||
awaiting_interaction = false
|
||||
|
||||
func reaction_is_active() -> bool:
|
||||
return reaction_mode != ""
|
||||
|
||||
func _tick_reaction(delta: float) -> void:
|
||||
if reaction_mode == "":
|
||||
return
|
||||
_reaction_timer -= delta
|
||||
if reaction_mode == "flee":
|
||||
if _reaction_timer <= 0.0 or (global_position - target_position).length() < 1.5:
|
||||
reaction_mode = ""
|
||||
queue_free()
|
||||
return
|
||||
if _reaction_timer <= 0.0:
|
||||
reaction_mode = ""
|
||||
|
||||
## Turn the body toward the reaction point without moving.
|
||||
func _face_reaction_point(delta: float) -> void:
|
||||
var to_point := reaction_point - global_position
|
||||
to_point.y = 0.0
|
||||
if to_point.length() < 0.1:
|
||||
return
|
||||
var target_yaw := atan2(-to_point.x, -to_point.z)
|
||||
rotation.y = lerp_angle(rotation.y, target_yaw, clampf(delta * 4.0, 0.0, 1.0))
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
if npc == null or npc.fsm == null:
|
||||
return
|
||||
_advance_fsm(delta)
|
||||
_tick_reaction(delta)
|
||||
if reaction_mode == "watch":
|
||||
velocity = Vector3.ZERO
|
||||
_face_reaction_point(delta)
|
||||
_animate(delta)
|
||||
return
|
||||
if reaction_mode == "flee":
|
||||
_move_toward_target(delta)
|
||||
_animate(delta)
|
||||
return
|
||||
_move_toward_target(delta)
|
||||
_animate(delta)
|
||||
|
||||
@@ -264,7 +340,7 @@ func _animate(delta: float) -> void:
|
||||
func _advance_fsm(delta: float) -> void:
|
||||
# Routine traffic despawns after a while once it has finished its walk, so
|
||||
# the crowd cap is not permanently occupied by idle standers.
|
||||
if ephemeral and arrived and npc.fsm.state != "LEAVING":
|
||||
if ephemeral and arrived and npc.fsm.current_state != "LEAVING":
|
||||
idle_s += delta
|
||||
if idle_s >= lifetime_s:
|
||||
leave_requested_by_lifetime = true
|
||||
@@ -291,7 +367,11 @@ func _move_toward_target(delta: float) -> void:
|
||||
if agent == null:
|
||||
_move_direct(delta)
|
||||
return
|
||||
agent.target_position = target_position
|
||||
# Re-assigning the target every physics frame invalidates the path, so
|
||||
# get_next_path_position() keeps returning the current position and the
|
||||
# avatar never moves. Only update the agent when the target changes.
|
||||
if agent.target_position != target_position:
|
||||
agent.target_position = target_position
|
||||
if agent.is_navigation_finished():
|
||||
if (global_position - target_position).length() < 3.0:
|
||||
_arrive()
|
||||
@@ -308,14 +388,32 @@ func _move_toward_target(delta: float) -> void:
|
||||
_move_direct(delta)
|
||||
return
|
||||
var next := agent.get_next_path_position()
|
||||
# Godot reports the current position as the first path point (on the navmesh
|
||||
# plane, so below the body) and only advances past it once the agent is within
|
||||
# path_desired_distance. Steering at the point we are standing on gives a
|
||||
# zero-length direction, and steering at any point merely "far enough" away can
|
||||
# pick the old start behind us. Follow the first path point that is genuinely
|
||||
# closer to the destination than we are.
|
||||
var path := agent.get_current_navigation_path()
|
||||
if path.size() >= 2:
|
||||
var goal: Vector3 = path[path.size() - 1]
|
||||
var here_to_goal := Vector2(goal.x - global_position.x, goal.z - global_position.z).length()
|
||||
for i in range(1, path.size()):
|
||||
var candidate: Vector3 = path[i]
|
||||
candidate.y = global_position.y
|
||||
var candidate_to_goal := Vector2(goal.x - candidate.x, goal.z - candidate.z).length()
|
||||
if candidate_to_goal < here_to_goal - 0.05:
|
||||
next = candidate
|
||||
break
|
||||
var dir := (next - global_position)
|
||||
dir.y = 0.0
|
||||
if dir.length() < 0.2:
|
||||
velocity = Vector3.ZERO
|
||||
return
|
||||
dir = dir.normalized()
|
||||
velocity.x = dir.x * 1.3
|
||||
velocity.z = dir.z * 1.3
|
||||
var speed := FLEE_SPEED if reaction_mode == "flee" else 1.3
|
||||
velocity.x = dir.x * speed
|
||||
velocity.z = dir.z * speed
|
||||
velocity.y -= 9.8 * delta
|
||||
look_at(global_position + Vector3(dir.x, 0, dir.z), Vector3.UP)
|
||||
move_and_slide()
|
||||
@@ -329,8 +427,9 @@ func _move_direct(delta: float) -> void:
|
||||
_arrive()
|
||||
return
|
||||
var dir := to_target.normalized()
|
||||
velocity.x = dir.x * 1.3
|
||||
velocity.z = dir.z * 1.3
|
||||
var speed := FLEE_SPEED if reaction_mode == "flee" else 1.3
|
||||
velocity.x = dir.x * speed
|
||||
velocity.z = dir.z * speed
|
||||
velocity.y -= 9.8 * delta
|
||||
look_at(global_position + Vector3(dir.x, 0, dir.z), Vector3.UP)
|
||||
move_and_slide()
|
||||
|
||||
Reference in new issue
Block a user