Feature: tile Y stagger — board no longer completely flat
Every tile now has a deterministic vertical offset (±0.15 units) in addition to its existing height variety, giving the board a natural uneven terrain look. Units placed on tiles and highlight rings account for the stagger offset. Move animations step through correct per-tile Y heights so units don't float or sink as they walk across the board. Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
@@ -160,7 +160,8 @@ var _prev_unit_hp : Dictionary = {} # instanceId → int, HP snapshot for damag
|
||||
var _prev_unit_pos: Dictionary = {} # instanceId → Vector2i, position snapshot for move detection
|
||||
var _move_anims : Dictionary = {} # instanceId → Tween (active movement tweens)
|
||||
var _last_attack_target_iid : String = "" # target of the most recent send_attack() call
|
||||
var _tile_heights : Dictionary = {} # "x,y" → float, world Y of tile top surface
|
||||
var _tile_heights : Dictionary = {} # "x,y" → float, height of tile block
|
||||
var _tile_y_bases : Dictionary = {} # "x,y" → float, vertical stagger offset
|
||||
|
||||
# Delayed rebuild: when animations need time to play we don't destroy unit nodes immediately.
|
||||
var _pending_rebuild : Dictionary = {} # latest state waiting for the delayed rebuild
|
||||
@@ -444,6 +445,7 @@ func _build_board(board: Dictionary) -> void:
|
||||
_unit_meshes.clear()
|
||||
_unit_bodies.clear()
|
||||
_tile_heights.clear()
|
||||
_tile_y_bases.clear()
|
||||
for tile: Dictionary in board.get("tiles", []):
|
||||
var coord : Dictionary = tile.get("coord", {})
|
||||
_add_tile(coord.get("x", 0), coord.get("y", 0),
|
||||
@@ -453,21 +455,19 @@ func _build_board(board: Dictionary) -> void:
|
||||
func _add_tile(x: int, y: int, affinity: String) -> void:
|
||||
var wp := _coord_to_world(x, y)
|
||||
|
||||
# Tiles with a 3D model get a small randomised height (0.8-1.0) for visual
|
||||
# variety. Placeholder tiles (no model assigned) are a fixed 0.5 height
|
||||
# so they read clearly as "undecorated" without towering over the board.
|
||||
# Every tile gets a seeded RNG for deterministic variety.
|
||||
# First roll: height (0.8-1.0 for model tiles, fixed 0.5 for placeholders).
|
||||
# Second roll: vertical stagger (±0.15) so the board isn't completely flat.
|
||||
var has_model : bool = not ContentCache.get_tile_model_url(affinity, "Square").is_empty()
|
||||
var h : float
|
||||
if has_model:
|
||||
var rng := RandomNumberGenerator.new()
|
||||
rng.seed = hash("%d_%d" % [x, y])
|
||||
h = rng.randf_range(0.8, 1.0)
|
||||
else:
|
||||
h = 0.5
|
||||
var rng := RandomNumberGenerator.new()
|
||||
rng.seed = hash("%d_%d" % [x, y])
|
||||
var h : float = rng.randf_range(0.8, 1.0) if has_model else 0.5
|
||||
var y_base : float = rng.randf_range(-0.15, 0.15)
|
||||
_tile_heights["%d,%d" % [x, y]] = h
|
||||
_tile_y_bases["%d,%d" % [x, y]] = y_base
|
||||
|
||||
var body := StaticBody3D.new()
|
||||
body.position = wp + Vector3(0, h * 0.5, 0) # centre at half-height so bottom = Y 0
|
||||
body.position = wp + Vector3(0, y_base + h * 0.5, 0)
|
||||
body.set_meta("tile_coord", Vector2i(x, y))
|
||||
body.set_meta("tile_height", h) # used by bottom-model loader
|
||||
|
||||
@@ -716,9 +716,10 @@ func _add_unit_mesh(unit: Dictionary, team_color: Color, is_enemy: bool = false)
|
||||
if pd.is_empty(): return
|
||||
var px : int = pd.get("x", 0)
|
||||
var py : int = pd.get("y", 0)
|
||||
var wp := _coord_to_world(px, py)
|
||||
var tile_h : float = _tile_heights.get("%d,%d" % [px, py], 1.0)
|
||||
var card_type : String = unit.get("cardType", "Spirit")
|
||||
var wp := _coord_to_world(px, py)
|
||||
var tile_h : float = _tile_heights.get("%d,%d" % [px, py], 1.0)
|
||||
var tile_base : float = _tile_y_bases.get("%d,%d" % [px, py], 0.0)
|
||||
var card_type : String = unit.get("cardType", "Spirit")
|
||||
var iid : String = unit.get("instanceId", "")
|
||||
var exhausted : bool = unit.get("isExhausted", false)
|
||||
|
||||
@@ -768,7 +769,7 @@ func _add_unit_mesh(unit: Dictionary, team_color: Color, is_enemy: bool = false)
|
||||
|
||||
body.add_child(shape)
|
||||
body.add_child(mi)
|
||||
body.position = wp + Vector3(0, y_offset, 0)
|
||||
body.position = wp + Vector3(0, tile_base + y_offset, 0)
|
||||
_units_root.add_child(body)
|
||||
_unit_meshes[iid] = mi
|
||||
_unit_bodies[iid] = body
|
||||
@@ -1279,20 +1280,30 @@ func _animate_unit_move(iid: String, from_coord: Vector2i, to_coord: Vector2i,
|
||||
step_angles.append(atan2(dir.x, -dir.z) - base_angle)
|
||||
prev_coord = step
|
||||
# Tween the body through each grid step, rotating the model to face each direction.
|
||||
var body_y := body.position.y
|
||||
# Compute how far above the tile top this unit sits so we can preserve that
|
||||
# offset as it moves across tiles of different stagger heights.
|
||||
var from_key := "%d,%d" % [from_coord.x, from_coord.y]
|
||||
var from_tile_top := _tile_y_bases.get(from_key, 0.0) + _tile_heights.get(from_key, 1.0)
|
||||
var unit_above := body.position.y - from_tile_top
|
||||
# Pre-compute per-step Y positions.
|
||||
var step_ys : Array[float] = []
|
||||
for step : Vector2i in path:
|
||||
var key := "%d,%d" % [step.x, step.y]
|
||||
step_ys.append(_tile_y_bases.get(key, 0.0) + _tile_heights.get(key, 1.0) + unit_above)
|
||||
var tween := create_tween()
|
||||
tween.set_ease(Tween.EASE_IN_OUT)
|
||||
tween.set_trans(Tween.TRANS_SINE)
|
||||
for i in path.size():
|
||||
var step : Vector2i = path[i]
|
||||
var wp := _coord_to_world(step.x, step.y)
|
||||
var facing_angle : float = step_angles[i] # captured per-iteration
|
||||
var facing_angle : float = step_angles[i]
|
||||
var step_y : float = step_ys[i]
|
||||
# Snap model rotation to face the movement direction before each step.
|
||||
tween.tween_callback(func() -> void:
|
||||
var m := _unit_meshes.get(iid) as Node3D
|
||||
if is_instance_valid(m):
|
||||
m.rotation.y = facing_angle)
|
||||
tween.tween_property(body, "position", Vector3(wp.x, body_y, wp.z), MOVE_STEP_SECS)
|
||||
tween.tween_property(body, "position", Vector3(wp.x, step_y, wp.z), MOVE_STEP_SECS)
|
||||
# Return to idle rotation and idle animation once movement finishes.
|
||||
tween.tween_callback(func() -> void:
|
||||
_move_anims.erase(iid)
|
||||
@@ -1378,9 +1389,10 @@ func _add_highlight(x: int, y: int, color: Color) -> void:
|
||||
mat.transparency = BaseMaterial3D.TRANSPARENCY_ALPHA
|
||||
mat.albedo_color.a = 0.75
|
||||
mi.material_override = mat
|
||||
# Position just above the tile top (varies per-tile).
|
||||
var _hi_tile_h : float = _tile_heights.get("%d,%d" % [x, y], 1.0)
|
||||
mi.position = _coord_to_world(x, y) + Vector3(0, _hi_tile_h + 0.08, 0)
|
||||
# Position just above the tile top (varies per-tile, accounting for stagger).
|
||||
var _hi_tile_h : float = _tile_heights.get("%d,%d" % [x, y], 1.0)
|
||||
var _hi_tile_base : float = _tile_y_bases.get("%d,%d" % [x, y], 0.0)
|
||||
mi.position = _coord_to_world(x, y) + Vector3(0, _hi_tile_base + _hi_tile_h + 0.08, 0)
|
||||
_hi_root.add_child(mi)
|
||||
print("[Highlight] added (%d,%d) hi_root children=%d" % [x, y, _hi_root.get_child_count()])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user