class_name Movement extends RefCounted ## Pure movement helpers. These run on the server (authoritative) and on the ## client (prediction). They must stay side-effect free so a client can replay ## them over a history of inputs and land on the same result as the server. ## Clamp a raw analogue/keyboard vector to a unit disc. static func sanitize_move(raw: Vector2) -> Vector2: if raw.length_squared() > 1.0: return raw.normalized() return raw ## One tick of player locomotion. Returns the new position. static func step_player(pos: Vector2, move: Vector2, speed: float, bounds: Vector2) -> Vector2: var next := pos + sanitize_move(move) * speed * SimConfig.TICK_DELTA next.x = clampf(next.x, -bounds.x, bounds.x) next.y = clampf(next.y, -bounds.y, bounds.y) return next ## Circle-vs-circle overlap test used for every hit in the game. static func circles_overlap(a: Vector2, ar: float, b: Vector2, br: float) -> bool: var r := ar + br return a.distance_squared_to(b) <= r * r ## True when a point has drifted outside the arena plus the cull margin. static func outside_arena(p: Vector2, margin: float = SimConfig.BULLET_CULL_MARGIN) -> bool: return absf(p.x) > SimConfig.ARENA_HALF.x + margin \ or absf(p.y) > SimConfig.ARENA_HALF.y + margin