If Bea needs the whole walk script
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.
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
