Token导航 LogoToken导航TokenDH.com
开发需要联网github未标认证来源可访问许可证需确认审计通过

unity-3d-mathUnity 3D math 命令行

Agent Skill

unity-3d-math 用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要围绕仓库状态、代码变更或协作事项进行整理时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

388

周安装

16

GitHub Stars

14

下载量

127
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:unity-3d-math(Unity 3D math 命令行)
来源仓库:https://github.com/nice-wolf-studio/unity-claude-skills
仓库路径:skills/unity-3d-math
安装命令:
npx skills add https://github.com/nice-wolf-studio/unity-claude-skills --skill unity-3d-math
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/nice-wolf-studio/unity-claude-skills --skill unity-3d-math

简介

用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息。

  • 适合在需要围绕仓库状态、代码变更或协作事项进行整理时使用。
  • 可结合来源仓库和原始 README 核验具体用法。
  • 安装前建议确认权限范围、维护状态及是否会触发联网或文件读写。
  • unity-3d-math 属于开发类 Skill,可作为该场景下的辅助能力补充。

SKILL.md

3D Math & Spatial Reasoning -- Correctness Patterns

Prerequisite skills: unity-scripting (Vector3/Quaternion API), unity-foundations (Transform, GameObjects), unity-physics (raycasting basics)

These patterns target the most dangerous Claude failure mode: plausible-looking math that compiles but produces wrong results. Each pattern documents Claude's default mistake and the correct Unity approach.


PATTERN: Coordinate Space -- TransformPoint vs TransformDirection

WHEN: Converting between local and world space

WRONG (Claude default):

// Using TransformDirection for a position offset
Vector3 worldPos = transform.TransformDirection(localOffset);

RIGHT:

// Positions: TransformPoint (applies position + rotation + scale)
Vector3 worldPos = transform.TransformPoint(localOffset);

// Directions: TransformDirection (applies rotation only, ignores scale)
Vector3 worldDir = transform.TransformDirection(localDir);

// Vectors: TransformVector (applies rotation + scale, no position)
Vector3 worldVec = transform.TransformVector(localVec);

GOTCHA: TransformDirection ignores scale -- if the parent has non-uniform scale and you need the direction scaled, use TransformVector. For the inverse operations, use InverseTransformPoint, InverseTransformDirection, InverseTransformVector.


PATTERN: Quaternion Multiplication Order

WHEN: Combining rotations (e.g., applying a local rotation on top of a world rotation)

WRONG (Claude default):

// "First rotate by A, then rotate by B"
transform.rotation = rotA * rotB; // Actually applies B first, then A

RIGHT:

// Quaternion multiplication applies RIGHT operand first
// "Apply B in A's space" = A * B
// Parent-then-child: parent * child
transform.rotation = worldRotation * localRotation;

// Example: rotate 45 degrees around Y, then tilt 30 degrees around local X
Quaternion yaw = Quaternion.AngleAxis(45f, Vector3.up);
Quaternion pitch = Quaternion.AngleAxis(30f, Vector3.right);
transform.rotation = yaw * pitch; // yaw is applied in world, pitch in yaw's local space

GOTCHA: This is the opposite of matrix multiplication reading order. If you think "first A then B", write A * B -- the right operand is applied in the left operand's local space.


PATTERN: Euler Angle Interpolation (Gimbal Lock)

WHEN: Smoothly rotating between two orientations

WRONG (Claude default):

// Interpolating euler angles directly
Vector3 currentEuler = Vector3.Lerp(startEuler, endEuler, t);
transform.eulerAngles = currentEuler;

RIGHT:

// Always interpolate quaternions, never euler angles
transform.rotation = Quaternion.Slerp(startRot, endRot, t);

// For small angles where performance matters, Lerp is acceptable
transform.rotation = Quaternion.Lerp(startRot, endRot, t); // Slightly faster, less accurate for large arcs

GOTCHA: Euler angles suffer from gimbal lock at 90-degree pitch and have discontinuities (e.g., 359 to 1 degree jumps through 358 degrees instead of 2). Quaternion.Slerp always takes the shortest path. Use Quaternion.Lerp only when the angular difference is small (< 45 degrees).


PATTERN: Quaternion.LookRotation Zero Vector

WHEN: Rotating an object to face a target direction

WRONG (Claude default):

Vector3 dir = target.position - transform.position;
transform.rotation = Quaternion.LookRotation(dir);

RIGHT:

Vector3 dir = target.position - transform.position;
if (dir.sqrMagnitude > 0.0001f) // Guard against zero/near-zero vector
{
    transform.rotation = Quaternion.LookRotation(dir, Vector3.up);
}

GOTCHA: LookRotation(Vector3.zero) produces NaN quaternion that silently corrupts the transform. The forward parameter does not need to be normalized (Unity normalizes internally), but it MUST be non-zero. Also fails if forward is exactly parallel to up -- the second parameter defaults to Vector3.up, which breaks if the target is directly above/below.


PATTERN: Never Modify Quaternion Components Directly

WHEN: Trying to zero out or modify a specific rotation axis

WRONG (Claude default):

// "Remove the X rotation"
Quaternion rot = transform.rotation;
rot.x = 0f;
transform.rotation = rot;

RIGHT:

// Extract euler, modify, rebuild
Vector3 euler = transform.eulerAngles;
euler.x = 0f;
transform.rotation = Quaternion.Euler(euler);

// Or use Quaternion factory methods
// Keep only Y rotation:
transform.rotation = Quaternion.Euler(0f, transform.eulerAngles.y, 0f);

GOTCHA: Quaternion x/y/z/w are NOT euler angles. They are components of a 4D unit quaternion. Setting .x = 0 produces a non-unit quaternion with undefined behavior. Always use factory methods: Quaternion.Euler(), Quaternion.AngleAxis(), Quaternion.LookRotation().


PATTERN: Float Comparison

WHEN: Comparing positions, distances, or any floating-point values

WRONG (Claude default):

if (transform.position == targetPosition) { /* arrived */ }
if (distance == 0f) { /* overlapping */ }

RIGHT:

// For positions: use sqrMagnitude with epsilon
if ((transform.position - targetPosition).sqrMagnitude < 0.0001f) { /* arrived */ }

// For single floats: use Mathf.Approximately
if (Mathf.Approximately(distance, 0f)) { /* close enough */ }

// For custom tolerance:
const float epsilon = 0.01f;
if (Mathf.Abs(a - b) < epsilon) { /* within tolerance */ }

GOTCHA: Vector3 == Vector3 in Unity does use an approximate comparison internally (epsilon ~1e-5), but it is often too tight for gameplay logic. Use explicit thresholds matching your game's precision needs. Never use == with calculated floats that accumulated error.


PATTERN: Vector3.Angle is Always Positive

WHEN: Determining turn direction (left vs right, clockwise vs counter-clockwise)

WRONG (Claude default):

float angle = Vector3.Angle(transform.forward, dirToTarget);
// angle is always 0-180, cannot tell left from right

RIGHT:

// SignedAngle returns -180 to +180 relative to the specified axis
float signedAngle = Vector3.SignedAngle(transform.forward, dirToTarget, Vector3.up);
// Positive = target is to the right, Negative = target is to the left (when axis is up)

GOTCHA: The sign depends on the axis parameter. With Vector3.up as axis: positive = clockwise when viewed from above. Choose the axis that matches your rotation plane. For 2D games using XY plane, use Vector3.forward as the axis.


PATTERN: Cross Product Order and Handedness

WHEN: Computing normals, perpendicular vectors, or winding order

WRONG (Claude default):

// Assuming right-hand rule
Vector3 normal = Vector3.Cross(edge1, edge2);

RIGHT:

// Unity uses a LEFT-handed coordinate system (Y-up, Z-forward)
// Cross product follows LEFT-hand rule:
// Cross(right, forward) = UP (not down)
Vector3 normal = Vector3.Cross(edge1, edge2);
// If normal points wrong way, swap operand order:
Vector3 flippedNormal = Vector3.Cross(edge2, edge1);

GOTCHA: Unity is left-handed (Y-up, X-right, Z-forward). OpenGL/Blender are right-handed. If you're porting math from a right-handed reference, you need to flip the cross product order OR negate one axis. Triangle winding is clockwise = front-facing in Unity.


PATTERN: sqrMagnitude for Distance Comparisons

WHEN: Comparing distances in performance-sensitive code (Update loops, many objects)

WRONG (Claude default):

// Vector3.Distance computes a square root every call
if (Vector3.Distance(a, b) < detectionRange)
{
    // detected
}

RIGHT:

// Compare squared distances -- avoids sqrt
float sqrRange = detectionRange * detectionRange;
if ((a - b).sqrMagnitude < sqrRange)
{
    // detected
}

GOTCHA: Cache sqrRange outside the loop -- do not recompute range * range per iteration. This optimization matters when checking N objects per frame (O(N) sqrt calls). For single checks, Vector3.Distance is perfectly fine -- do not micro-optimize one-off calls.


PATTERN: Camera.ScreenToWorldPoint Z Depth

WHEN: Converting a screen position (mouse, touch) to a world position

WRONG (Claude default):

// z=0 gives a point ON the camera's near plane, not in the scene
Vector3 worldPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);

RIGHT:

// Set z to the desired distance from the camera
Vector3 screenPos = Input.mousePosition;
screenPos.z = desiredDistance; // Distance from camera along its forward axis
Vector3 worldPos = Camera.main.ScreenToWorldPoint(screenPos);

GOTCHA: The z component of the input vector is the distance from the camera in world units along the camera's forward direction. For perspective cameras, z=0 returns a point at the camera's position. For orthographic cameras, z doesn't affect x/y but still sets depth. To place objects on a ground plane, use Physics.Raycast with Camera.ScreenPointToRay instead.


PATTERN: Camera.ViewportToWorldPoint

WHEN: Placing objects at viewport edges (HUD bounds, screen limits)

WRONG (Claude default):

// Missing z depth -- returns a point at the camera
Vector3 topRight = Camera.main.ViewportToWorldPoint(new Vector3(1f, 1f, 0f));

RIGHT:

// z = distance from camera where you want the world point
float distFromCamera = 10f;
Vector3 topRight = Camera.main.ViewportToWorldPoint(new Vector3(1f, 1f, distFromCamera));
Vector3 bottomLeft = Camera.main.ViewportToWorldPoint(new Vector3(0f, 0f, distFromCamera));

GOTCHA: Viewport coordinates are normalized: (0,0) = bottom-left, (1,1) = top-right. The z value is NOT a Z world coordinate -- it is the distance from the camera. This matters for perspective cameras where the frustum widens with distance.


PATTERN: Plane.Raycast Semantics

WHEN: Finding where a ray intersects a mathematical plane

WRONG (Claude default):

Plane groundPlane = new Plane(Vector3.up, 0f);
float enter;
groundPlane.Raycast(ray, out enter);
Vector3 hitPoint = ray.GetPoint(enter); // Using enter without checking return value

RIGHT:

Plane groundPlane = new Plane(Vector3.up, 0f); // Normal=up, distance=0 (XZ plane at origin)
float enter;
if (groundPlane.Raycast(ray, out enter))
{
    Vector3 hitPoint = ray.GetPoint(enter);
}
// If returns false, the ray points away from the plane (enter is negative)

GOTCHA: Plane.Raycast returns true only when the ray intersects the plane's front side (the side the normal points toward). If the ray origin is behind the plane or pointing away, it returns false and enter is negative. The Plane constructor new Plane(normal, distance) -- the distance is the signed distance from origin along the normal. new Plane(Vector3.up, 5f) creates a plane at y = -5, NOT y = 5. Use new Plane(Vector3.up, new Vector3(0, 5, 0)) for a plane at y = 5.


PATTERN: Bounds is Always Axis-Aligned (AABB)

WHEN: Checking spatial overlap or containment of rotated objects

WRONG (Claude default):

// Assuming bounds rotates with the object
if (renderer.bounds.Contains(point))
{
    // This is an AABB check, not an OBB check
}

RIGHT:

// renderer.bounds is an AXIS-ALIGNED bounding box in WORLD space
// It expands to encompass the rotated mesh, making it larger than the actual object
Bounds aabb = renderer.bounds;

// For oriented checks, use the collider or manual OBB:
// Option 1: Use a collider (accurate to shape)
Collider col = GetComponent<Collider>();
Vector3 closest = col.ClosestPoint(point);
bool inside = (closest - point).sqrMagnitude < 0.0001f;

// Option 2: Transform point to local space for local-space AABB check
Vector3 localPoint = transform.InverseTransformPoint(point);
Bounds localBounds = meshFilter.sharedMesh.bounds; // Local-space bounds
bool containsLocal = localBounds.Contains(localPoint);

GOTCHA: Renderer.bounds returns world-space AABB. Rotating an object makes its AABB grow (a rotated cube's AABB is larger than the cube). Mesh.bounds is local-space. For Bounds.Intersects(other), both must be in the same space. Collider.bounds is also AABB -- for precise shape checks use Physics.ComputePenetration or Collider.ClosestPoint.


PATTERN: Transform Hierarchy Scale Inheritance

WHEN: Working with parent/child transforms that have non-uniform scale

WRONG (Claude default):

// Assuming scale is independent
transform.localScale = Vector3.one; // Visually one-to-one? Not if parent is scaled

RIGHT:

// lossyScale gives the approximate world-space scale (read-only)
Vector3 worldScale = transform.lossyScale;

// To set a specific world-space scale on a child:
Vector3 parentScale = transform.parent.lossyScale;
transform.localScale = new Vector3(
    desiredWorldScale.x / parentScale.x,
    desiredWorldScale.y / parentScale.y,
    desiredWorldScale.z / parentScale.z
);

GOTCHA: lossyScale is only approximate when the hierarchy contains rotation + non-uniform scale (skew). Unity does not support skew in transforms, so lossyScale may not perfectly represent the visual scale. Avoid non-uniform scale on parents of rotated children. SetParent(parent, true) preserves world position/rotation/scale; SetParent(parent, false) keeps local values -- choose intentionally.


Common Patterns Quick Reference

NeedMethodSpace
Position local-to-worldTransformPointlocal -> world
Position world-to-localInverseTransformPointworld -> local
Direction local-to-worldTransformDirectionrotation only
Direction world-to-localInverseTransformDirectionrotation only
Vector local-to-worldTransformVectorrotation + scale
Angle between vectorsVector3.Angleunsigned 0-180
Signed angleVector3.SignedAngle-180 to +180
Dot product > 0vectors face same hemisphere
Dot product == 0vectors are perpendicular
Dot product < 0vectors face opposite directions
Mouse to world rayCamera.ScreenPointToRayscreen -> world
Mouse to world pointScreenToWorldPoint + z depthscreen -> world
Viewport edge to worldViewportToWorldPoint + z depthviewport -> world

Related Skills

  • unity-scripting -- Vector3, Quaternion, Time API reference
  • unity-foundations -- Transform API, parent/child hierarchies
  • unity-physics -- Raycasting, collider spatial queries
  • unity-physics-queries -- Physics query correctness patterns

Additional Resources

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

37.8%
按下载量换算48

Claude

31.52%
按下载量换算40

Cursor

18.56%
按下载量换算24

Gemini CLI

8.94%
按下载量换算11

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills