#29: cutscene kit and roof luggage
CutsceneKit (static, shared by FarmersReturn and the coming opening intro): make_car / add_engine, the tinted farmer mannequins (make_farmer, anim_of), route_curve / reversed / place_on_curve for any point list, make_camera / move_camera / follow_camera / face, set_hud, and the Letterbox overlay with a caller-set skip hint. FarmersReturn now uses it and behaves as before. load_roof piles National Lampoon style luggage on car_002's rack: farm-pack bags and crates, four primitive suitcases, and a hatbox, stacked from the roof found in the car mesh's AABB and vertices, three straps pulled taut over the pile's real outline, and a rolled mattress lashed off the right side. No collision. Luggage.sway(delta, turn_rate, accel) leans it out on turns and forward when braking; the ending's drive uses it. test_flow: the ending's car is loaded, the pile sits on the car mesh's AABB top, and it sways the right way. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
5dbad4c915
commit
c009260d4a
4 changed files with 773 additions and 133 deletions
|
|
@ -7,13 +7,12 @@ extends Node3D
|
|||
## camera follows the car, then frames the yard; the HUD hides behind letterbox bars. Fire,
|
||||
## interact, or Space / Enter / A skips to the end. finished is emitted once it's
|
||||
## over (or skipped), and EndPanel shows the final assessment over the scene.
|
||||
## Built when it starts, after the game is over, so nothing is created during play.
|
||||
## Built when it starts, after the game is over, so nothing is created during play. The car (with
|
||||
## its roof luggage, which sways on the turns and tips forward as it stops), the farmers, the
|
||||
## camera moves, and the letterbox come from CutsceneKit, which the opening intro shares.
|
||||
|
||||
signal finished
|
||||
|
||||
const CAR_SCENE := "res://assets/farm/ithappy/farm/prefabs/assets/transport/car_002.tscn"
|
||||
const FARMER_SCENE := "res://assets/kaykit_characters/characters/Mannequin_Medium.glb"
|
||||
const ANIMATIONS := "res://game/resources/player_animations.res"
|
||||
## The road from the south along the east side, in at GapDriveway, through the farmyard to the
|
||||
## parking spot east of the house (game/LAYOUT.md); the car faces the way it drives.
|
||||
const ROUTE: Array[Vector3] = [
|
||||
|
|
@ -30,7 +29,6 @@ const SCARECROW_SPOT := Vector3(24.6, 0.0, -34.0)
|
|||
const YARD_CAMERA := Vector3(28.0, 10.0, -45.5)
|
||||
const YARD_LOOK := Vector3(24.8, 0.8, -30.8)
|
||||
const WALK_SPEED := 2.0
|
||||
const TINTS: Array[Color] = [Color(0.35, 0.5, 0.85), Color(0.85, 0.45, 0.4)]
|
||||
## Seconds: honk after parking, farmers out, then waving, cheering, and the end.
|
||||
const OUT_AT := 0.9
|
||||
const WAVE_TIME := 2.2
|
||||
|
|
@ -47,13 +45,14 @@ var _car: Node3D
|
|||
var _engine: AudioStreamPlayer3D
|
||||
var _curve := Curve3D.new()
|
||||
var _driven: float = 0.0
|
||||
var _speed: float = 0.0 # the last step's, for the luggage's sway
|
||||
var _parked_for: float = 0.0
|
||||
var _farmers: Array[Node3D] = []
|
||||
var _anims: Array[AnimationPlayer] = []
|
||||
var _camera: Camera3D
|
||||
var _previous_camera: Camera3D
|
||||
var _stage_left: float = 0.0
|
||||
var _overlay: CanvasLayer
|
||||
var _overlay: CutsceneKit.Letterbox
|
||||
var _caption: Label
|
||||
|
||||
|
||||
|
|
@ -76,59 +75,17 @@ func start() -> void:
|
|||
elapsed = 0.0
|
||||
stage = "drive"
|
||||
_driven = 0.0
|
||||
_speed = DRIVE_SPEED
|
||||
_parked_for = 0.0
|
||||
for p in ROUTE:
|
||||
_curve.add_point(p)
|
||||
for i in range(1, ROUTE.size() - 1): # round the corners
|
||||
var t := (ROUTE[i + 1] - ROUTE[i - 1]) * 0.25
|
||||
_curve.set_point_in(i, -t)
|
||||
_curve.set_point_out(i, t)
|
||||
_car = (load(CAR_SCENE) as PackedScene).instantiate() as Node3D
|
||||
add_child(_car)
|
||||
for body in _car.find_children("*", "CollisionObject3D", true, false):
|
||||
(body as CollisionObject3D).collision_layer = 0
|
||||
_engine = AudioStreamPlayer3D.new()
|
||||
_engine.bus = &"SFX"
|
||||
_engine.unit_size = 10.0
|
||||
_engine.volume_db = -6.0
|
||||
if sim.audio != null:
|
||||
_engine.stream = sim.audio.stream_of("truck_engine")
|
||||
_car.add_child(_engine)
|
||||
if _engine.stream != null:
|
||||
_engine.play()
|
||||
_curve = CutsceneKit.route_curve(ROUTE)
|
||||
_car = CutsceneKit.make_car(self)
|
||||
_engine = CutsceneKit.add_engine(_car, sim.audio)
|
||||
_place_car(0.0)
|
||||
var library := load(ANIMATIONS) as AnimationLibrary
|
||||
for i in 2:
|
||||
var root := Node3D.new()
|
||||
root.visible = false
|
||||
add_child(root)
|
||||
var model := (load(FARMER_SCENE) as PackedScene).instantiate() as Node3D
|
||||
root.add_child(model)
|
||||
for mi in model.find_children("*", "MeshInstance3D", true, false):
|
||||
var m := mi as MeshInstance3D
|
||||
var base := m.get_active_material(0)
|
||||
if base is BaseMaterial3D:
|
||||
var tinted := (base as BaseMaterial3D).duplicate() as BaseMaterial3D
|
||||
tinted.albedo_color = TINTS[i]
|
||||
m.material_override = tinted
|
||||
var straw := StandardMaterial3D.new() # a straw sun hat for the trip
|
||||
straw.albedo_color = Color(0.92, 0.8, 0.45)
|
||||
for part in [[0.62, 0.05, 2.12], [0.34, 0.26, 2.26]]: # brim, crown: radius, height, y
|
||||
var mesh := CylinderMesh.new()
|
||||
mesh.top_radius = part[0]
|
||||
mesh.bottom_radius = part[0]
|
||||
mesh.height = part[1]
|
||||
var hat := MeshInstance3D.new()
|
||||
hat.mesh = mesh
|
||||
hat.position = Vector3(0.0, part[2], 0.0)
|
||||
hat.material_override = straw
|
||||
model.add_child(hat)
|
||||
var anim := AnimationPlayer.new()
|
||||
root.add_child(anim)
|
||||
anim.root_node = anim.get_path_to(model)
|
||||
anim.add_animation_library(&"", library)
|
||||
_farmers.append(root)
|
||||
_anims.append(anim)
|
||||
var farmer := CutsceneKit.make_farmer(self, CutsceneKit.FARMER_TINTS[i])
|
||||
farmer.visible = false
|
||||
_farmers.append(farmer)
|
||||
_anims.append(CutsceneKit.anim_of(farmer))
|
||||
# The scarecrow waits by the yard (in co-op, both, side by side).
|
||||
for a in sim.avatars:
|
||||
var at := SCARECROW_SPOT + Vector3(1.6, 0.0, 0.6) * a.slot
|
||||
|
|
@ -140,14 +97,12 @@ func start() -> void:
|
|||
a.body.net_yaw = yaw
|
||||
a.body.start_channel(&"Idle_A")
|
||||
_previous_camera = get_viewport().get_camera_3d()
|
||||
_camera = Camera3D.new()
|
||||
_camera.fov = 45.0
|
||||
add_child(_camera)
|
||||
_camera.make_current()
|
||||
_follow_camera(1.0)
|
||||
_camera = CutsceneKit.make_camera(self)
|
||||
CutsceneKit.follow_camera(_camera, _car, 1.0)
|
||||
if sim.audio != null:
|
||||
sim.audio.focus = _car
|
||||
_build_overlay()
|
||||
_overlay = CutsceneKit.make_letterbox(self, "The farmers are on their way home", "[Space / Enter / A] skip")
|
||||
_caption = _overlay.caption
|
||||
_set_hud(false)
|
||||
|
||||
|
||||
|
|
@ -158,10 +113,13 @@ func skip() -> void:
|
|||
_driven = _curve.get_baked_length()
|
||||
_place_car(_driven)
|
||||
_stop_engine()
|
||||
var luggage := CutsceneKit.luggage_of(_car)
|
||||
if luggage != null:
|
||||
luggage.settle()
|
||||
for i in 2:
|
||||
_farmers[i].visible = true
|
||||
_farmers[i].global_position = FARMER_SPOTS[i]
|
||||
_face(_farmers[i], SCARECROW_SPOT)
|
||||
CutsceneKit.face(_farmers[i], SCARECROW_SPOT)
|
||||
_anims[i].play(&"Cheering")
|
||||
_frame_yard(1.0)
|
||||
_finish()
|
||||
|
|
@ -179,6 +137,7 @@ func clear() -> void:
|
|||
_engine = null
|
||||
_camera = null
|
||||
_overlay = null
|
||||
_caption = null
|
||||
_curve = Curve3D.new()
|
||||
if sim != null:
|
||||
_set_hud(true)
|
||||
|
|
@ -202,9 +161,15 @@ func step(delta: float) -> void:
|
|||
var length := _curve.get_baked_length()
|
||||
var left := length - _driven
|
||||
var speed := DRIVE_SPEED * clampf(left / 9.0, 0.18, 1.0) # ease into the spot
|
||||
var was := _driven
|
||||
var heading := _car.rotation.y
|
||||
_driven = minf(_driven + speed * delta, length)
|
||||
_place_car(_driven)
|
||||
_follow_camera(delta)
|
||||
if delta > 0.0: # the luggage leans out on the turns and tips forward as the car stops
|
||||
var moved := (_driven - was) / delta
|
||||
CutsceneKit.sway_luggage(_car, delta, angle_difference(heading, _car.rotation.y) / delta, (moved - _speed) / delta)
|
||||
_speed = moved
|
||||
CutsceneKit.follow_camera(_camera, _car, delta)
|
||||
if _driven >= length:
|
||||
_parked_for += delta
|
||||
if _parked_for >= 0.15 and _engine != null and _engine.playing:
|
||||
|
|
@ -220,6 +185,7 @@ func step(delta: float) -> void:
|
|||
_anims[i].play(&"Walking_A", 0.1)
|
||||
"walk":
|
||||
_frame_yard(delta)
|
||||
CutsceneKit.sway_luggage(_car, delta, 0.0, 0.0)
|
||||
var arrived := 0
|
||||
for i in 2:
|
||||
var f := _farmers[i]
|
||||
|
|
@ -229,12 +195,12 @@ func step(delta: float) -> void:
|
|||
arrived += 1
|
||||
continue
|
||||
f.global_position += to.limit_length(WALK_SPEED * delta)
|
||||
_face(f, f.global_position + to)
|
||||
CutsceneKit.face(f, f.global_position + to)
|
||||
if arrived == 2:
|
||||
stage = "wave"
|
||||
_stage_left = WAVE_TIME
|
||||
for i in 2:
|
||||
_face(_farmers[i], SCARECROW_SPOT)
|
||||
CutsceneKit.face(_farmers[i], SCARECROW_SPOT)
|
||||
_anims[i].play(&"Waving", 0.15)
|
||||
if sim.audio != null:
|
||||
sim.audio.play("victory")
|
||||
|
|
@ -242,6 +208,7 @@ func step(delta: float) -> void:
|
|||
_caption.text = "The farmers are home!"
|
||||
"wave", "cheer":
|
||||
_frame_yard(delta)
|
||||
CutsceneKit.sway_luggage(_car, delta, 0.0, 0.0)
|
||||
_stage_left -= delta
|
||||
if _stage_left <= 0.0:
|
||||
if stage == "wave":
|
||||
|
|
@ -263,46 +230,16 @@ func _finish() -> void:
|
|||
|
||||
|
||||
func _set_hud(on: bool) -> void:
|
||||
if sim.hud != null and sim.hud.get_parent() is CanvasLayer:
|
||||
(sim.hud.get_parent() as CanvasLayer).visible = on
|
||||
CutsceneKit.set_hud(sim, on)
|
||||
|
||||
|
||||
func _place_car(distance: float) -> void:
|
||||
var length := _curve.get_baked_length()
|
||||
var at := _curve.sample_baked(distance, true)
|
||||
var ahead := _curve.sample_baked(minf(distance + 1.0, length), true)
|
||||
var behind := _curve.sample_baked(maxf(distance - 1.0, 0.0), true)
|
||||
var dir := ahead - behind
|
||||
dir.y = 0.0
|
||||
if dir.length_squared() > 1e-6:
|
||||
_car.rotation = Vector3(0.0, atan2(dir.x, dir.z), 0.0)
|
||||
_car.global_position = Vector3(at.x, 0.0, at.z)
|
||||
|
||||
|
||||
## Behind and above the car, looking a little ahead of it.
|
||||
func _follow_camera(delta: float) -> void:
|
||||
var fwd := _car.global_basis.z
|
||||
var want := _car.global_position - fwd * 11.0 + Vector3(0.0, 8.0, 0.0) + _car.global_basis.x * 3.0
|
||||
var look := _car.global_position + fwd * 4.0 + Vector3(0.0, 1.0, 0.0)
|
||||
_move_camera(want, look, delta, 2.5)
|
||||
CutsceneKit.place_on_curve(_car, _curve, distance)
|
||||
|
||||
|
||||
## A wide shot of the yard from the north-east: the car, the porch, and the scarecrow.
|
||||
func _frame_yard(delta: float) -> void:
|
||||
_move_camera(YARD_CAMERA, YARD_LOOK, delta, 1.2)
|
||||
|
||||
|
||||
func _move_camera(want: Vector3, look: Vector3, delta: float, rate: float) -> void:
|
||||
var k := 1.0 - exp(-rate * delta) if delta < 1.0 else 1.0
|
||||
_camera.global_position = _camera.global_position.lerp(want, k) if _camera.global_position != Vector3.ZERO else want
|
||||
var target := _camera.global_transform.looking_at(look, Vector3.UP)
|
||||
_camera.global_basis = _camera.global_basis.slerp(target.basis, k).orthonormalized() if k < 1.0 else target.basis
|
||||
|
||||
|
||||
func _face(node: Node3D, at: Vector3) -> void:
|
||||
var d := at - node.global_position
|
||||
if Vector2(d.x, d.z).length_squared() > 1e-6:
|
||||
node.rotation.y = atan2(d.x, d.z)
|
||||
CutsceneKit.move_camera(_camera, YARD_CAMERA, YARD_LOOK, delta, 1.2)
|
||||
|
||||
|
||||
func _stop_engine() -> void:
|
||||
|
|
@ -310,38 +247,6 @@ func _stop_engine() -> void:
|
|||
_engine.stop()
|
||||
|
||||
|
||||
func _build_overlay() -> void:
|
||||
_overlay = CanvasLayer.new()
|
||||
_overlay.layer = 5
|
||||
add_child(_overlay)
|
||||
for top in [true, false]:
|
||||
var bar := ColorRect.new()
|
||||
bar.color = Color.BLACK
|
||||
bar.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
_overlay.add_child(bar)
|
||||
bar.set_anchors_and_offsets_preset(Control.PRESET_TOP_WIDE if top else Control.PRESET_BOTTOM_WIDE)
|
||||
if top:
|
||||
bar.offset_bottom = 96.0
|
||||
else:
|
||||
bar.offset_top = -96.0
|
||||
_caption = Label.new()
|
||||
_caption.text = "The farmers are on their way home"
|
||||
_caption.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
||||
_caption.add_theme_font_size_override("font_size", 38)
|
||||
_caption.add_theme_color_override("font_color", Color(0.95, 0.85, 0.55))
|
||||
_overlay.add_child(_caption)
|
||||
_caption.set_anchors_and_offsets_preset(Control.PRESET_TOP_WIDE)
|
||||
_caption.offset_top = 22.0
|
||||
var hint := Label.new()
|
||||
hint.text = "[Space / Enter / A] skip"
|
||||
hint.add_theme_font_size_override("font_size", 22)
|
||||
hint.add_theme_color_override("font_color", Color(0.8, 0.8, 0.75))
|
||||
_overlay.add_child(hint)
|
||||
hint.set_anchors_and_offsets_preset(Control.PRESET_BOTTOM_RIGHT)
|
||||
hint.offset_left = -360.0
|
||||
hint.offset_top = -70.0
|
||||
|
||||
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if not running or done:
|
||||
return
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue