↓
iaen.es Devlog Leer en español

Gotic · 3 min read

A town on top of a plateau: testing in Godot that the climb can be walked

Altomira sits 58 m up, at the end of a 713 m road. On a grid the climb looked gentle; measured metre by metre, it was right at the edge of what the character can walk up.

#towns#testing#world#godot

A town on top of a plateau: testing in Godot that the climb can be walked

Altomira is the hardest town to reach. It sits on top of the eastern plateau, 58 m above sea level, and its road is the longest on the island: 713 m from Brumacosta's arch, climbing through the interior. When you arrive you see the arch with the town's name in purple and, behind the houses, a stone watchtower with battlements and a yellow flag. A brazier burns at the top, visible from up to 600 m away. Mara, the lookout, says you can see the whole island from the tower. Teo, the goatherd, warns you that the climb is long, but the road goes "where goats can go". And if you're in a hurry, there's a flying broom back in Brumacosta.

How it's built

The town comes out of the shared builder with "landmark": "tower". The tower has collision, so you can walk around it or land on top with the broom. The tricky part wasn't the tower but making sure you can get there on foot.

The character can climb slopes up to 46°, which in the game is a slope of 0.305 (Island.slope_at). The road up to the plateau was computed outside the game over the terrain and stored in the mod as a list of 35 points. But you can't just assume a list of points is walkable, so the check has two parts:

  1. Metre by metre. The test walks each stretch of the road in one-metre steps, recording the lowest height (it can't touch water) and the steepest slope, which must stay at 0.29 or below. I left that margin to 0.305 because the terrain can get a bit steeper between samples.
  2. With physics. It finds the steepest point on the whole road, puts the character 10 m below it and pushes them uphill with the real physics engine to a point 10 m above. If they haven't got within 1.5 m of the goal after 360 steps, the test fails.
for frame in range(360):
	var direction: Vector3 = goal - main.player.position
	closest = minf(closest, Vector2(direction.x, direction.z).length())
	if closest < 1.5:
		break
	main.player.move_input = Vector2(direction.x, -direction.z).normalized()
	await t.physics_frame

Both checks live in tests/village_checks.gd and all three new towns use them, but they only get serious in Altomira. Caleta's road never goes above 0.05 and Vega de Poniente's above 0.09. The plateau climb peaks at 0.28, a hair below the player's limit, and the character makes it up with physics.

What went wrong

The road was searched on a 4 m grid, and on that grid the plateau climb gave a comfortable slope of 0.21. Walked metre by metre, it came out at 0.28. Between two grid points the terrain can be much steeper than at the points themselves, and the grid can't see it. Had I trusted it, I'd have thought there was plenty of margin, when that stretch is actually 33% steeper and one step away from the limit. That's why the test doesn't look at the road's points but at everything in between.

The tower gets its own test: a ray cast from above must hit it more than 11 m above the ground, which confirms it's solid and taller than the houses.

Still unverified

That slope has only been climbed by the character pushed by a test, never by a thumb on a joystick. With real fingers on a touchscreen, I don't know whether 713 m of climbing feels long or whether the 0.28 stretch gets stuck. FPS for this town on a phone hasn't been measured: the APK got installed, but the phone was locked. This screenshot cost 323 draw calls and about 151,000 triangles on PC.

More from Gotic →