Skip to reading
The Sock Exchange, Part 4: Trouble After Closing

If Bea needs the whole walk script

Edition 0.86.4.2

0.86.4.2 edition with appended native sprite-motion lessons. Earlier chapters, reference counts and screenshots retain their original edition context.

Download PDFView PDF page

TUTORIAL 04 • REFERENCE

Use this page if you skipped the movement polish at the end of Part 3. If page 13 already gave Bea all four directions outside, you’re done.

1 Make sure walk_front and walk_back exist on Bea. If either is missing, draw two 32 × 48 frames side by side in a 64 × 48 PNG. Draw her face for bea_front or the back of her hair for bea_back. Alternate the planted shoe. Import each as a two-column Sprite Sheet and add each walking state in Character Designer. Use its matching sheet, loop on, 5 FPS.

2 In Scripts create or open the GDScript sorting_motion. Turn on Keep global instance alive. Enter the following code, using the indentation shown. Click Validate, then Apply Changes. Save and play.

Code example
func _process(_delta):
    if not is_instance_valid(Runtime):
        return
    if Runtime.scene_id not in ["sorting_room", "service_yard"]:
        return
    var a = Runtime.player
    if not is_instance_valid(a):
        return
    var s = a.get_node_or_null("Stage2DSprite")
    if s == null:
        return
    var depth = clampf((a.position.z + 2.0) / 6.0, 0.0, 1.0)
    a.scale = Vector3.ONE * lerpf(0.65, 1.0, depth)
    var v = a.velocity
    if absf(v.x) + absf(v.z) < 0.05:
        return
    var pose = "walk"
    if absf(v.z) > absf(v.x):
        pose = "walk_front" if v.z > 0 else "walk_back"
    if s.sprite_frames.has_animation(pose):
        s.flip_h = pose == "walk" and v.x < 0
        if s.animation != pose:
            s.play(pose)

Why it works X is left and right on the pavement. Z runs from the back to the front. The script compares the two amounts of movement and picks the drawing for the larger one. The line with flip_h turns the right-facing side walk around for a trip to the left.

Editor and play images captured in PCA 3D Adventure Studio 0.86.3.4 on Linux. The project settings and record IDs apply across desktop editions. Panel layout can vary with screen size and editor version.

PCA 3D Adventure Studio / 19

Page 19 of 20Permalink
Go to page

Continue your 2D adventure

  1. Part 1The Sock Exchange, Part 1: Your First 2D Adventure
  2. Part 2The Sock Exchange, Part 2: The Missing Laundry
  3. Part 3The Sock Exchange, Part 3: The Dryer Conspiracy
  4. Part 4The Sock Exchange, Part 4: Trouble After Closing
  5. Part 5The Sock Exchange, Part 5: The Midnight Pickup
  6. Part 6The Sock Exchange, Part 6: Closing Time