[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6KRBRAG45E4786XMQ6YKJAE":3,"skill-same:01M6KRBRAG45E4786XMQ6YKJAE":76},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":34,"linkOnly":35,"markdownContent":36,"markdownBody":37,"frontMatter":38,"refName":39,"commitSha":40,"skillDirectory":41,"forksCount":42,"repositoryHtmlUrl":43,"repositoryHomepageUrl":6,"ownerHtmlUrl":44,"ownerBlogUrl":45,"ownerDescription":46,"updatedAt":47,"install":48,"resources":61},"01M6KRBRAG45E4786XMQ6YKJAE","math-essentials",null,"Use when implementing game math — vectors, transforms, interpolation, curves, random number generation, and common geometric recipes","jame581\u002FGodotPrompter","jame581","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F21112138?v=4","01M6KR3KEQ9Z30WVJRR2E2ZVXE","Jan Mesarč","01M6KR3KJVRMPDSMASQPBCBVK3",964,"MIT","https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fmath-essentials\u002FSKILL.md",[],[19,20,21,22,23,24,25,26,27,28,29,30,31,32,33],"math","math essentials","game","common","use","generation","vectors","recipes","transforms","random","number","implementing","interpolation","when","curves","2026-11-10 10:12:30",false,"---\nname: math-essentials\ndescription: Use when implementing game math — vectors, transforms, interpolation, curves, random number generation, and common geometric recipes\n---\n\n# Game Math in Godot 4.3+\n\nAll examples target Godot 4.3+ with no deprecated APIs. GDScript is shown first, then C#.\n\n> **Related skills:** **player-controller** for movement physics, **ai-navigation** for pathfinding math, **camera-system** for camera interpolation, **tween-animation** for easing curves, **physics-system** for collision math.\n\n---\n\n## 1. Vector Operations\n\n### Essential Vector Methods\n\n| Method                  | Returns   | Description                                   |\n|-------------------------|-----------|-----------------------------------------------|\n| `length()`              | `float`   | Magnitude of the vector                       |\n| `length_squared()`      | `float`   | Squared magnitude (faster, skip sqrt)         |\n| `normalized()`          | `Vector`  | Unit vector (length 1) in the same direction  |\n| `distance_to(b)`        | `float`   | Distance between two points                   |\n| `distance_squared_to(b)` | `float` | Squared distance (faster for comparisons)     |\n| `direction_to(b)`       | `Vector`  | Normalized direction from this to b           |\n| `angle_to(b)`           | `float`   | Angle in radians between two vectors          |\n| `angle_to_point(b)`     | `float`   | Angle from this point to b (2D)               |\n| `dot(b)`                | `float`   | Dot product                                   |\n| `cross(b)`              | `float\u002FVector3` | Cross product (2D returns float, 3D returns vector) |\n| `rotated(angle)`        | `Vector2` | Rotated by radians (2D)                       |\n| `move_toward(to, delta)` | `Vector` | Move toward target by at most delta           |\n| `clamp(min, max)`       | `Vector`  | Clamp each component                          |\n| `snapped(step)`         | `Vector`  | Snap to grid                                  |\n| `reflect(normal)`       | `Vector`  | Reflect off a surface                         |\n| `bounce(normal)`        | `Vector`  | Bounce off a surface (inverted reflect)       |\n| `slide(normal)`         | `Vector`  | Slide along a surface                         |\n\n### Direction and Distance\n\n```gdscript\n# Get direction from A to B (normalized)\nvar dir: Vector2 = global_position.direction_to(target.global_position)\n\n# Get distance\nvar dist: float = global_position.distance_to(target.global_position)\n\n# Use squared distance for comparisons (faster — avoids sqrt)\nif global_position.distance_squared_to(target.global_position) \u003C detection_range * detection_range:\n    chase_target()\n```\n\n```csharp\nVector2 dir = GlobalPosition.DirectionTo(target.GlobalPosition);\nfloat dist = GlobalPosition.DistanceTo(target.GlobalPosition);\n\nif (GlobalPosition.DistanceSquaredTo(target.GlobalPosition) \u003C detectionRange * detectionRange)\n    ChaseTarget();\n```\n\n### Dot Product\n\nThe dot product tells you how aligned two vectors are.\n\n```gdscript\n# Is the target in front of us? (dot > 0 = in front, \u003C 0 = behind)\nvar forward: Vector2 = Vector2.RIGHT.rotated(rotation)\nvar to_target: Vector2 = global_position.direction_to(target.global_position)\nvar dot: float = forward.dot(to_target)\n\nif dot > 0.7:  # roughly within ~45° cone\n    print(\"Target is ahead\")\nelif dot \u003C -0.7:\n    print(\"Target is behind\")\n```\n\n```csharp\nVector2 forward = Vector2.Right.Rotated(Rotation);\nVector2 toTarget = GlobalPosition.DirectionTo(target.GlobalPosition);\nfloat dot = forward.Dot(toTarget);\n\nif (dot > 0.7f) GD.Print(\"Target is ahead\");\n```\n\n### Cross Product (3D)\n\nThe cross product gives a vector perpendicular to two input vectors.\n\n```gdscript\n# Get the surface normal from two edge vectors\nvar edge1: Vector3 = vertex_b - vertex_a\nvar edge2: Vector3 = vertex_c - vertex_a\nvar normal: Vector3 = edge1.cross(edge2).normalized()\n```\n\n```csharp\nVector3 edge1 = vertexB - vertexA;\nVector3 edge2 = vertexC - vertexA;\nVector3 normal = edge1.Cross(edge2).Normalized();\n```\n\n---\n\n## 2. Transforms\n\n### Transform2D\n\nA 2D transform holds position, rotation, and scale.\n\n```gdscript\n# Get the global transform\nvar xform: Transform2D = global_transform\n\n# Convert between local and global space\nvar local_point: Vector2 = to_local(global_point)\nvar world_point: Vector2 = to_global(local_point)\n\n# Apply transform to a point\nvar transformed: Vector2 = xform * Vector2(10, 0)  # point in local space → global\n\n# Inverse transform\nvar local: Vector2 = xform.affine_inverse() * global_point\n```\n\n```csharp\nTransform2D xform = GlobalTransform;\nVector2 localPoint = ToLocal(globalPoint);\nVector2 worldPoint = ToGlobal(localPoint);\nVector2 transformed = xform * new Vector2(10, 0);\nVector2 local = xform.AffineInverse() * globalPoint;\n```\n\n### Transform3D & Basis\n\n```gdscript\n# Basis holds rotation and scale as 3 column vectors\nvar basis: Basis = global_transform.basis\n\n# Forward direction (looking along -Z in Godot)\nvar forward: Vector3 = -basis.z\nvar right: Vector3 = basis.x\nvar up: Vector3 = basis.y\n\n# Look at a target\nlook_at(target.global_position, Vector3.UP)\n\n# Rotate around an axis\nrotate_y(deg_to_rad(90.0))\nrotate_object_local(Vector3.UP, deg_to_rad(45.0))\n\n# Interpolate between two transforms (smooth transition)\nvar a: Transform3D = $Start.global_transform\nvar b: Transform3D = $End.global_transform\nglobal_transform = a.interpolate_with(b, 0.5)  # halfway\n```\n\n```csharp\nBasis basis = GlobalTransform.Basis;\nVector3 forward = -basis.Z;\nVector3 right = basis.X;\nVector3 up = basis.Y;\n\nLookAt(target.GlobalPosition, Vector3.Up);\nRotateY(Mathf.DegToRad(90.0f));\n\nTransform3D a = GetNode\u003CNode3D>(\"Start\").GlobalTransform;\nTransform3D b = GetNode\u003CNode3D>(\"End\").GlobalTransform;\nGlobalTransform = a.InterpolateWith(b, 0.5f);\n```\n\n### is_orthonormal() (Godot 4.7+)\n\n`Basis.is_orthonormal()` (const) returns `true` if the basis is *orthogonal* (axes perpendicular to each other) **and** *normalized* (every axis has length `1.0`) — especially useful during physics calculations. It complements `orthonormalized()`: check first, and only re-orthonormalize when accumulated floating-point drift has denormalized the basis.\n\n```gdscript\nif not global_transform.basis.is_orthonormal():\n    global_transform.basis = global_transform.basis.orthonormalized()\n```\n\n```csharp\n\u002F\u002F GodotSharp has no IsOrthonormal(); compare with the orthonormalized basis instead.\nBasis basis = GlobalTransform.Basis;\nif (!basis.IsEqualApprox(basis.Orthonormalized()))\n{\n    GlobalTransform = new Transform3D(basis.Orthonormalized(), GlobalPosition);\n}\n```\n\n---\n\n## 3. Interpolation\n\n### lerp — Linear Interpolation\n\n```gdscript\n# Interpolate between two values (t = 0.0 to 1.0)\nvar mid: float = lerp(0.0, 100.0, 0.5)   # 50.0\nvar pos: Vector2 = lerp(start_pos, end_pos, 0.75)  # 75% of the way\n\n# Smooth following — lerp with delta for frame-rate independence\nfunc _process(delta: float) -> void:\n    position = position.lerp(target_position, 5.0 * delta)\n```\n\n```csharp\nfloat mid = Mathf.Lerp(0.0f, 100.0f, 0.5f);\nVector2 pos = startPos.Lerp(endPos, 0.75f);\n\npublic override void _Process(double delta)\n{\n    Position = Position.Lerp(targetPosition, 5.0f * (float)delta);\n}\n```\n\n> **Warning:** `lerp(a, b, speed * delta)` is frame-rate dependent and never fully reaches the target. For precise movement, use `move_toward()` instead.\n\n### move_toward — Fixed-Speed Approach\n\n```gdscript\n# Move exactly `speed * delta` units toward target each frame\nposition.x = move_toward(position.x, target_x, speed * delta)\n\n# Vector version\nposition = position.move_toward(target_position, speed * delta)\n```\n\n```csharp\nfloat newX = Mathf.MoveToward(Position.X, targetX, speed * (float)delta);\nPosition = Position.MoveToward(targetPosition, speed * (float)delta);\n```\n\n### slerp — Spherical Interpolation\n\nFor smooth rotation interpolation (preserves arc, not straight line).\n\n```gdscript\n# Quaternion slerp for smooth 3D rotation\nvar current_quat: Quaternion = global_transform.basis.get_rotation_quaternion()\nvar target_quat: Quaternion = target_transform.basis.get_rotation_quaternion()\nvar result: Quaternion = current_quat.slerp(target_quat, 5.0 * delta)\nglobal_transform.basis = Basis(result)\n```\n\n```csharp\nQuaternion currentQuat = GlobalTransform.Basis.GetRotationQuaternion();\nQuaternion targetQuat = targetTransform.Basis.GetRotationQuaternion();\nQuaternion result = currentQuat.Slerp(targetQuat, 5.0f * (float)delta);\nGlobalTransform = new Transform3D(new Basis(result), GlobalPosition);\n```\n\n### smoothstep — S-Curve Easing\n\n```gdscript\n# Returns 0.0 when x \u003C= from, 1.0 when x >= to, smooth curve between\nvar t: float = smoothstep(0.0, 10.0, distance)  # 0→1 as distance goes 0→10\n\n# Useful for soft thresholds (fog density, volume falloff)\nvar fog_intensity: float = smoothstep(50.0, 100.0, camera_distance)\n```\n\n### cubic_interpolate — Smooth Path Following\n\n```gdscript\n# Smooth interpolation using 4 control points (catmull-rom style)\nvar point: Vector2 = p1.cubic_interpolate(p2, p0, p3, t)\n# p0 = before start, p1 = start, p2 = end, p3 = after end\n```\n\n### Interpolation Comparison\n\n| Function           | Speed          | Reaches Target | Smooth | Use For                    |\n|--------------------|----------------|----------------|--------|----------------------------|\n| `lerp(a, b, t)`   | Variable       | Only at t=1    | Yes    | UI transitions, blending   |\n| `move_toward()`    | Constant       | Yes            | No     | Movement, timers           |\n| `slerp()`          | Variable       | Only at t=1    | Yes    | Rotation blending          |\n| `smoothstep()`     | S-curve        | Soft threshold | Yes    | Fog, volume, thresholds    |\n| `cubic_interpolate()` | Variable    | Only at t=1    | Very   | Paths, camera rails        |\n\n---\n\n## 4. Curves and Paths\n\n`Curve` resource for value-over-time (e.g., damage falloff curves). `Path2D` \u002F `Path3D` for spatial paths sampled by `PathFollow2D` \u002F `PathFollow3D` — use for moving platforms, missile guidance, camera rails.\n\n> See [references\u002Fcurves-and-paths.md](references\u002Fcurves-and-paths.md) for `Curve` setup, Path nodes, PathFollow properties.\n\n---\n\n## 5. Random Number Generation\n\nGlobal functions (`randf()`, `randi() % N`, `randf_range(a, b)`) for one-shot randomness. `RandomNumberGenerator` for seeded, reproducible randomness (procgen, replay, save-state). Weighted selection via cumulative-sum or alias method.\n\n> See [references\u002Frandom-numbers.md](references\u002Frandom-numbers.md) for full GDScript on each pattern, plus `FastNoiseLite` for procedural generation noise.\n\n---\n\n## 6. Common Game Math Recipes\n\nFive recipes: **look at target** (2D `Vector2.angle_to_point`), **orbit around a point** (polar coordinates), **sine-wave bob** (floating UI elements, treasure), **angle wrapping** (-PI..PI canonicalization), **clamped approach with deadzone** (analog input + small-input ignore).\n\n> See [references\u002Fgame-math-recipes.md](references\u002Fgame-math-recipes.md) for ready-to-use code on each recipe.\n\n---\n\n## 7. Common Pitfalls\n\n| Symptom                              | Cause                                       | Fix                                                              |\n|--------------------------------------|----------------------------------------------|------------------------------------------------------------------|\n| `lerp` never reaches target          | Using `lerp(a, b, speed * delta)` each frame | Use `move_toward()` for exact arrival                            |\n| Rotation jumps at 180°               | Using `lerp` instead of `lerp_angle`         | Always use `lerp_angle()` for angle interpolation                |\n| Object faces wrong direction (3D)    | Forgot Godot uses -Z as forward              | Forward direction is `-global_transform.basis.z`                 |\n| Distance check too slow              | Calling `distance_to` on many objects        | Use `distance_squared_to` and compare against `range * range`    |\n| Direction is `(0, 0)` unexpectedly   | `normalized()` of a zero vector returns zero | Check `length() > 0` (or `is_zero_approx()`) before using it     |\n| Transform interpolation looks wrong  | Lerping euler angles instead of quaternions  | Use `Quaternion.slerp()` or `Transform3D.interpolate_with()`    |\n| Random results repeat after restart  | Using `RandomNumberGenerator` with fixed seed | Godot 4.x auto-seeds global RNG; for `RandomNumberGenerator` use `randomize()` or set `seed` |\n| Noise values are all ~0              | `frequency` too low                          | Increase `FastNoiseLite.frequency` (try 0.01–0.1)               |\n\n---\n\n## 8. Implementation Checklist\n\n- [ ] Distance comparisons use `distance_squared_to()` for performance\n- [ ] Angle interpolation uses `lerp_angle()`, not `lerp()`\n- [ ] 3D forward direction is `-transform.basis.z`, not `+z`\n- [ ] `move_toward()` is used when exact arrival at target is needed\n- [ ] `lerp(a, b, speed * delta)` is understood as frame-rate dependent smooth following, not exact movement\n- [ ] `RandomNumberGenerator` is used for deterministic\u002Fseeded randomness (procedural generation, replays)\n- [ ] Noise-based generation uses `FastNoiseLite` with appropriate frequency and seed\n- [ ] Weighted random selection is used for loot tables and probability-based systems\n- [ ] Path following uses `PathFollow2D\u002F3D` with `progress` or `progress_ratio`\n- [ ] Quaternion slerp is used for 3D rotation interpolation instead of euler angles\n","# Game Math in Godot 4.3+\n\nAll examples target Godot 4.3+ with no deprecated APIs. GDScript is shown first, then C#.\n\n> **Related skills:** **player-controller** for movement physics, **ai-navigation** for pathfinding math, **camera-system** for camera interpolation, **tween-animation** for easing curves, **physics-system** for collision math.\n\n---\n\n## 1. Vector Operations\n\n### Essential Vector Methods\n\n| Method                  | Returns   | Description                                   |\n|-------------------------|-----------|-----------------------------------------------|\n| `length()`              | `float`   | Magnitude of the vector                       |\n| `length_squared()`      | `float`   | Squared magnitude (faster, skip sqrt)         |\n| `normalized()`          | `Vector`  | Unit vector (length 1) in the same direction  |\n| `distance_to(b)`        | `float`   | Distance between two points                   |\n| `distance_squared_to(b)` | `float` | Squared distance (faster for comparisons)     |\n| `direction_to(b)`       | `Vector`  | Normalized direction from this to b           |\n| `angle_to(b)`           | `float`   | Angle in radians between two vectors          |\n| `angle_to_point(b)`     | `float`   | Angle from this point to b (2D)               |\n| `dot(b)`                | `float`   | Dot product                                   |\n| `cross(b)`              | `float\u002FVector3` | Cross product (2D returns float, 3D returns vector) |\n| `rotated(angle)`        | `Vector2` | Rotated by radians (2D)                       |\n| `move_toward(to, delta)` | `Vector` | Move toward target by at most delta           |\n| `clamp(min, max)`       | `Vector`  | Clamp each component                          |\n| `snapped(step)`         | `Vector`  | Snap to grid                                  |\n| `reflect(normal)`       | `Vector`  | Reflect off a surface                         |\n| `bounce(normal)`        | `Vector`  | Bounce off a surface (inverted reflect)       |\n| `slide(normal)`         | `Vector`  | Slide along a surface                         |\n\n### Direction and Distance\n\n```gdscript\n# Get direction from A to B (normalized)\nvar dir: Vector2 = global_position.direction_to(target.global_position)\n\n# Get distance\nvar dist: float = global_position.distance_to(target.global_position)\n\n# Use squared distance for comparisons (faster — avoids sqrt)\nif global_position.distance_squared_to(target.global_position) \u003C detection_range * detection_range:\n    chase_target()\n```\n\n```csharp\nVector2 dir = GlobalPosition.DirectionTo(target.GlobalPosition);\nfloat dist = GlobalPosition.DistanceTo(target.GlobalPosition);\n\nif (GlobalPosition.DistanceSquaredTo(target.GlobalPosition) \u003C detectionRange * detectionRange)\n    ChaseTarget();\n```\n\n### Dot Product\n\nThe dot product tells you how aligned two vectors are.\n\n```gdscript\n# Is the target in front of us? (dot > 0 = in front, \u003C 0 = behind)\nvar forward: Vector2 = Vector2.RIGHT.rotated(rotation)\nvar to_target: Vector2 = global_position.direction_to(target.global_position)\nvar dot: float = forward.dot(to_target)\n\nif dot > 0.7:  # roughly within ~45° cone\n    print(\"Target is ahead\")\nelif dot \u003C -0.7:\n    print(\"Target is behind\")\n```\n\n```csharp\nVector2 forward = Vector2.Right.Rotated(Rotation);\nVector2 toTarget = GlobalPosition.DirectionTo(target.GlobalPosition);\nfloat dot = forward.Dot(toTarget);\n\nif (dot > 0.7f) GD.Print(\"Target is ahead\");\n```\n\n### Cross Product (3D)\n\nThe cross product gives a vector perpendicular to two input vectors.\n\n```gdscript\n# Get the surface normal from two edge vectors\nvar edge1: Vector3 = vertex_b - vertex_a\nvar edge2: Vector3 = vertex_c - vertex_a\nvar normal: Vector3 = edge1.cross(edge2).normalized()\n```\n\n```csharp\nVector3 edge1 = vertexB - vertexA;\nVector3 edge2 = vertexC - vertexA;\nVector3 normal = edge1.Cross(edge2).Normalized();\n```\n\n---\n\n## 2. Transforms\n\n### Transform2D\n\nA 2D transform holds position, rotation, and scale.\n\n```gdscript\n# Get the global transform\nvar xform: Transform2D = global_transform\n\n# Convert between local and global space\nvar local_point: Vector2 = to_local(global_point)\nvar world_point: Vector2 = to_global(local_point)\n\n# Apply transform to a point\nvar transformed: Vector2 = xform * Vector2(10, 0)  # point in local space → global\n\n# Inverse transform\nvar local: Vector2 = xform.affine_inverse() * global_point\n```\n\n```csharp\nTransform2D xform = GlobalTransform;\nVector2 localPoint = ToLocal(globalPoint);\nVector2 worldPoint = ToGlobal(localPoint);\nVector2 transformed = xform * new Vector2(10, 0);\nVector2 local = xform.AffineInverse() * globalPoint;\n```\n\n### Transform3D & Basis\n\n```gdscript\n# Basis holds rotation and scale as 3 column vectors\nvar basis: Basis = global_transform.basis\n\n# Forward direction (looking along -Z in Godot)\nvar forward: Vector3 = -basis.z\nvar right: Vector3 = basis.x\nvar up: Vector3 = basis.y\n\n# Look at a target\nlook_at(target.global_position, Vector3.UP)\n\n# Rotate around an axis\nrotate_y(deg_to_rad(90.0))\nrotate_object_local(Vector3.UP, deg_to_rad(45.0))\n\n# Interpolate between two transforms (smooth transition)\nvar a: Transform3D = $Start.global_transform\nvar b: Transform3D = $End.global_transform\nglobal_transform = a.interpolate_with(b, 0.5)  # halfway\n```\n\n```csharp\nBasis basis = GlobalTransform.Basis;\nVector3 forward = -basis.Z;\nVector3 right = basis.X;\nVector3 up = basis.Y;\n\nLookAt(target.GlobalPosition, Vector3.Up);\nRotateY(Mathf.DegToRad(90.0f));\n\nTransform3D a = GetNode\u003CNode3D>(\"Start\").GlobalTransform;\nTransform3D b = GetNode\u003CNode3D>(\"End\").GlobalTransform;\nGlobalTransform = a.InterpolateWith(b, 0.5f);\n```\n\n### is_orthonormal() (Godot 4.7+)\n\n`Basis.is_orthonormal()` (const) returns `true` if the basis is *orthogonal* (axes perpendicular to each other) **and** *normalized* (every axis has length `1.0`) — especially useful during physics calculations. It complements `orthonormalized()`: check first, and only re-orthonormalize when accumulated floating-point drift has denormalized the basis.\n\n```gdscript\nif not global_transform.basis.is_orthonormal():\n    global_transform.basis = global_transform.basis.orthonormalized()\n```\n\n```csharp\n\u002F\u002F GodotSharp has no IsOrthonormal(); compare with the orthonormalized basis instead.\nBasis basis = GlobalTransform.Basis;\nif (!basis.IsEqualApprox(basis.Orthonormalized()))\n{\n    GlobalTransform = new Transform3D(basis.Orthonormalized(), GlobalPosition);\n}\n```\n\n---\n\n## 3. Interpolation\n\n### lerp — Linear Interpolation\n\n```gdscript\n# Interpolate between two values (t = 0.0 to 1.0)\nvar mid: float = lerp(0.0, 100.0, 0.5)   # 50.0\nvar pos: Vector2 = lerp(start_pos, end_pos, 0.75)  # 75% of the way\n\n# Smooth following — lerp with delta for frame-rate independence\nfunc _process(delta: float) -> void:\n    position = position.lerp(target_position, 5.0 * delta)\n```\n\n```csharp\nfloat mid = Mathf.Lerp(0.0f, 100.0f, 0.5f);\nVector2 pos = startPos.Lerp(endPos, 0.75f);\n\npublic override void _Process(double delta)\n{\n    Position = Position.Lerp(targetPosition, 5.0f * (float)delta);\n}\n```\n\n> **Warning:** `lerp(a, b, speed * delta)` is frame-rate dependent and never fully reaches the target. For precise movement, use `move_toward()` instead.\n\n### move_toward — Fixed-Speed Approach\n\n```gdscript\n# Move exactly `speed * delta` units toward target each frame\nposition.x = move_toward(position.x, target_x, speed * delta)\n\n# Vector version\nposition = position.move_toward(target_position, speed * delta)\n```\n\n```csharp\nfloat newX = Mathf.MoveToward(Position.X, targetX, speed * (float)delta);\nPosition = Position.MoveToward(targetPosition, speed * (float)delta);\n```\n\n### slerp — Spherical Interpolation\n\nFor smooth rotation interpolation (preserves arc, not straight line).\n\n```gdscript\n# Quaternion slerp for smooth 3D rotation\nvar current_quat: Quaternion = global_transform.basis.get_rotation_quaternion()\nvar target_quat: Quaternion = target_transform.basis.get_rotation_quaternion()\nvar result: Quaternion = current_quat.slerp(target_quat, 5.0 * delta)\nglobal_transform.basis = Basis(result)\n```\n\n```csharp\nQuaternion currentQuat = GlobalTransform.Basis.GetRotationQuaternion();\nQuaternion targetQuat = targetTransform.Basis.GetRotationQuaternion();\nQuaternion result = currentQuat.Slerp(targetQuat, 5.0f * (float)delta);\nGlobalTransform = new Transform3D(new Basis(result), GlobalPosition);\n```\n\n### smoothstep — S-Curve Easing\n\n```gdscript\n# Returns 0.0 when x \u003C= from, 1.0 when x >= to, smooth curve between\nvar t: float = smoothstep(0.0, 10.0, distance)  # 0→1 as distance goes 0→10\n\n# Useful for soft thresholds (fog density, volume falloff)\nvar fog_intensity: float = smoothstep(50.0, 100.0, camera_distance)\n```\n\n### cubic_interpolate — Smooth Path Following\n\n```gdscript\n# Smooth interpolation using 4 control points (catmull-rom style)\nvar point: Vector2 = p1.cubic_interpolate(p2, p0, p3, t)\n# p0 = before start, p1 = start, p2 = end, p3 = after end\n```\n\n### Interpolation Comparison\n\n| Function           | Speed          | Reaches Target | Smooth | Use For                    |\n|--------------------|----------------|----------------|--------|----------------------------|\n| `lerp(a, b, t)`   | Variable       | Only at t=1    | Yes    | UI transitions, blending   |\n| `move_toward()`    | Constant       | Yes            | No     | Movement, timers           |\n| `slerp()`          | Variable       | Only at t=1    | Yes    | Rotation blending          |\n| `smoothstep()`     | S-curve        | Soft threshold | Yes    | Fog, volume, thresholds    |\n| `cubic_interpolate()` | Variable    | Only at t=1    | Very   | Paths, camera rails        |\n\n---\n\n## 4. Curves and Paths\n\n`Curve` resource for value-over-time (e.g., damage falloff curves). `Path2D` \u002F `Path3D` for spatial paths sampled by `PathFollow2D` \u002F `PathFollow3D` — use for moving platforms, missile guidance, camera rails.\n\n> See [references\u002Fcurves-and-paths.md](references\u002Fcurves-and-paths.md) for `Curve` setup, Path nodes, PathFollow properties.\n\n---\n\n## 5. Random Number Generation\n\nGlobal functions (`randf()`, `randi() % N`, `randf_range(a, b)`) for one-shot randomness. `RandomNumberGenerator` for seeded, reproducible randomness (procgen, replay, save-state). Weighted selection via cumulative-sum or alias method.\n\n> See [references\u002Frandom-numbers.md](references\u002Frandom-numbers.md) for full GDScript on each pattern, plus `FastNoiseLite` for procedural generation noise.\n\n---\n\n## 6. Common Game Math Recipes\n\nFive recipes: **look at target** (2D `Vector2.angle_to_point`), **orbit around a point** (polar coordinates), **sine-wave bob** (floating UI elements, treasure), **angle wrapping** (-PI..PI canonicalization), **clamped approach with deadzone** (analog input + small-input ignore).\n\n> See [references\u002Fgame-math-recipes.md](references\u002Fgame-math-recipes.md) for ready-to-use code on each recipe.\n\n---\n\n## 7. Common Pitfalls\n\n| Symptom                              | Cause                                       | Fix                                                              |\n|--------------------------------------|----------------------------------------------|------------------------------------------------------------------|\n| `lerp` never reaches target          | Using `lerp(a, b, speed * delta)` each frame | Use `move_toward()` for exact arrival                            |\n| Rotation jumps at 180°               | Using `lerp` instead of `lerp_angle`         | Always use `lerp_angle()` for angle interpolation                |\n| Object faces wrong direction (3D)    | Forgot Godot uses -Z as forward              | Forward direction is `-global_transform.basis.z`                 |\n| Distance check too slow              | Calling `distance_to` on many objects        | Use `distance_squared_to` and compare against `range * range`    |\n| Direction is `(0, 0)` unexpectedly   | `normalized()` of a zero vector returns zero | Check `length() > 0` (or `is_zero_approx()`) before using it     |\n| Transform interpolation looks wrong  | Lerping euler angles instead of quaternions  | Use `Quaternion.slerp()` or `Transform3D.interpolate_with()`    |\n| Random results repeat after restart  | Using `RandomNumberGenerator` with fixed seed | Godot 4.x auto-seeds global RNG; for `RandomNumberGenerator` use `randomize()` or set `seed` |\n| Noise values are all ~0              | `frequency` too low                          | Increase `FastNoiseLite.frequency` (try 0.01–0.1)               |\n\n---\n\n## 8. Implementation Checklist\n\n- [ ] Distance comparisons use `distance_squared_to()` for performance\n- [ ] Angle interpolation uses `lerp_angle()`, not `lerp()`\n- [ ] 3D forward direction is `-transform.basis.z`, not `+z`\n- [ ] `move_toward()` is used when exact arrival at target is needed\n- [ ] `lerp(a, b, speed * delta)` is understood as frame-rate dependent smooth following, not exact movement\n- [ ] `RandomNumberGenerator` is used for deterministic\u002Fseeded randomness (procedural generation, replays)\n- [ ] Noise-based generation uses `FastNoiseLite` with appropriate frequency and seed\n- [ ] Weighted random selection is used for loot tables and probability-based systems\n- [ ] Path following uses `PathFollow2D\u002F3D` with `progress` or `progress_ratio`\n- [ ] Quaternion slerp is used for 3D rotation interpolation instead of euler angles\n",{"name":5,"description":7},"master","d7b26cdb5fae14d4ef7b713c5bf259395e75c3c6","skills\u002Fmath-essentials",63,"https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter","https:\u002F\u002Fgithub.com\u002Fjame581","https:\u002F\u002Fjanmesarc.online\u002F","Software engineer. My biggest passion is game development.","2026-11-14 20:45:49",{"source":8,"skillName":5,"commands":49,"prompt":59,"zipAvailable":60},[50,53,56],{"tool":51,"command":52},"npx","npx skills add jame581\u002FGodotPrompter --skill math-essentials",{"tool":54,"command":55},"bunx","bunx skills add jame581\u002FGodotPrompter --skill math-essentials",{"tool":57,"command":58},"pnpm","pnpm dlx skills add jame581\u002FGodotPrompter --skill math-essentials","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fmath-essentials\u002FSKILL.md",true,[62,68,72],{"path":63,"resourceType":64,"resourceTypeDesc":65,"sizeBytes":66,"sourceHtmlUrl":67},"references\u002Fcurves-and-paths.md","REFERENCE","参考文档",1895,"https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fmath-essentials\u002Freferences\u002Fcurves-and-paths.md",{"path":69,"resourceType":64,"resourceTypeDesc":65,"sizeBytes":70,"sourceHtmlUrl":71},"references\u002Fgame-math-recipes.md",2727,"https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fmath-essentials\u002Freferences\u002Fgame-math-recipes.md",{"path":73,"resourceType":64,"resourceTypeDesc":65,"sizeBytes":74,"sourceHtmlUrl":75},"references\u002Frandom-numbers.md",2967,"https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fmath-essentials\u002Freferences\u002Frandom-numbers.md",[77,97,118,147,171,186],{"skillNo":78,"name":79,"nameZh":6,"description":80,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":81,"categories":82,"keywords":83,"publishedAt":34},"01M6KRFE5BR2PSD08ZKDAS66R7","xr-development","Use when building VR\u002FAR\u002FXR applications — OpenXR setup, XROrigin3D, hand tracking, controllers, passthrough, and Meta Quest deployment in Godot 4.3+","https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fxr-development\u002FSKILL.md",[],[84,85,32,86,87,88,89,90,91,92,93,23,94,95,96],"xr development","development","deployment","godot","vr","setup","tracking","godot 4","ar","hand","Meta","applications","quest",{"skillNo":98,"name":99,"nameZh":6,"description":100,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":101,"categories":102,"keywords":103,"publishedAt":34},"01M6KRF8GZTG1TAS506MFBSGFC","web-services","Use when a Godot game calls a web server — HTTPRequest, downloads, REST\u002FJSON APIs, auth headers, WebSocketPeer clients, TLS, retries, and keeping secrets out of the build. Not for game networking\u002FRPCs (multiplayer-basics) or browser export (web-export)","https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fweb-services\u002FSKILL.md",[],[104,105,106,107,108,109,110,111,23,32,87,112,113,114,115,116,117],"web services","web","services","tls","retries","calling","auth","downloads","clients","headers","secrets","json","build","REST",{"skillNo":119,"name":120,"nameZh":6,"description":121,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":122,"categories":123,"keywords":129,"publishedAt":34},"01M6KRF38Q4WSKAYFS56PG87T0","web-export","Use when shipping a Godot game to the browser — Web export preset options, threads vs no-threads and COOP\u002FCOEP headers, hosting on itch.io or your own server, PWA, JavaScriptBridge, user:\u002F\u002F persistence, audio and input limits, and load size","https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fweb-export\u002FSKILL.md",[124],{"categoryNo":125,"categoryName":126,"taxonomyType":127,"taxonomyTypeDesc":128},"01JBSEEDCAT000000000000016","图像与多媒体","SCENARIO","使用场景",[105,130,131,132,133,134,135,136,113,137,138,32,139,140,141,21,142,143,23,144,145,146],"export","web export","threads","limits","shipping","size","options","hosting","input","Coop","preset","browser","io","load","pwa","Audio","server",{"skillNo":148,"name":149,"nameZh":6,"description":150,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":151,"categories":152,"keywords":161,"publishedAt":34},"01M6KREYFETEBH62ZTN6EZH2X3","using-godot-prompter","Bootstrap skill — establishes how to find and use GodotPrompter skills, with platform-specific tool mapping","https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fusing-godot-prompter\u002FSKILL.md",[153,156],{"categoryNo":154,"categoryName":155,"taxonomyType":127,"taxonomyTypeDesc":128},"01JBSEEDCAT000000000000023","Skill与智能体开发",{"categoryNo":157,"categoryName":158,"taxonomyType":159,"taxonomyTypeDesc":160},"01JBSEEDCAT000000000000032","设计师","PROFESSION","适用职业",[87,162,163,164,165,23,166,167,168,169,170],"using godot prompter","find","with","bootstrap","tool","platform","mapping","how","how to",{"skillNo":172,"name":173,"nameZh":6,"description":174,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":175,"categories":176,"keywords":177,"publishedAt":34},"01M6KRER5G7EQWKGAFN8QJKQ69","tween-animation","Use when implementing tweens — property animation, method tweening, chaining, parallel sequences, easing, and common UI\u002Fgameplay motion recipes","https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Ftween-animation\u002FSKILL.md",[],[178,179,23,180,181,182,183,184,26,22,30,32,185],"tween animation","Animation","motion","parallel","gameplay","chaining","ui","sequences",{"skillNo":187,"name":188,"nameZh":6,"description":189,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":190,"categories":191,"keywords":192,"publishedAt":34},"01M6KREKGCQMVDV8WX7HWX8BZG","state-machine","Use when building a state machine or refactoring logic into one — enum, node, and resource-based FSM patterns with trade-offs. Not for adding states to an existing one","https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fstate-machine\u002FSKILL.md",[],[193,194,195,87,32,196,197,198,199,200,164,23,30,201],"state","state machine","machine","patterns","node","fsm","state machines","trade","trade-offs"]