跳到正文
Skillpedia
通用编程6.6k · #13840

roblox-physics

它能做什么

该技能讲解如何让 Roblox 部件表现出物理行为,例如下落、碰撞或被投射物击中。适合构建载具、投射物或移动物体的开发者。

适用场景

  • ✓当你需要 Roblox 中的部件下落、弹跳、碰撞,或受力移动时。
  • ✓当你希望投射物或命中检测能够可靠运作,而不依赖 Touched 时。
  • ✓当旧的 BodyMover 脚本或约束对象损坏或不稳定时。

技能链接

https://github.com/gamedev-skills/awesome-gamedev-agent-skills/blob/main/skills/other-engines/roblox-physics/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/gamedev-skills/awesome-gamedev-agent-skills/blob/main/skills/other-engines/roblox-physics/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“我的 Roblox 投射物穿过了墙,我该怎样让它可靠地撞上墙?”

每周 5 个新技能,1 分钟读完。

工作原理

该技能帮助智能体为每个目标选择合适的机制,例如物理模拟、瞬时冲量或服务器命中检查,并设置符合设计的碰撞和查询规则。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Roblox physics

Choose deliberately between simulation, character control, hit detection, and visual-only motion; they are different jobs. Targets Roblox's rolling platform APIs. Pair with physics-tuning for engine-neutral stability and feel.

When to use

  • Use for BasePart assemblies, constraints, collision/query policy, ray/overlap queries, forces, impulses, moving physical objects, network ownership, or physics cleanup.
  • Use when Touched is unreliable/security-sensitive, parts tunnel or jitter, a mechanism breaks when anchored, or old BodyMover patterns appear.

When not to use: ordinary Humanoid lifecycle/control belongs to roblox-characters; remote validation belongs to roblox-networking; decorative UI/world motion may only need a tween.

Decide the system first

Goal Mechanism
sustained physical interaction unanchored assembly + modern constraints/forces
instantaneous physical change ApplyImpulse / ApplyAngularImpulse
kinematic platform/path controlled pivot/transform with an explicit passenger policy
character locomotion Humanoid/custom character controller (roblox-characters)
authoritative hit test server raycast/overlap with filters and gameplay validation
cosmetic trail/recoil local visual motion; no gameplay authority

Workflow

  1. Inspect the mechanism. In Studio, visualize assemblies, anchors, constraints, collision groups, massless parts, and network owners. Identify the assembly root and intended authority.
  2. Define interaction policy. Write the collision-group matrix and separately decide CanCollide, CanTouch, and CanQuery. These flags are not interchangeable. Register groups in the Studio Collision Groups editor or with Workspace:RegisterCollisionGroup() and Workspace:CollisionGroupSetCollidable(); the PhysicsService collision-group methods are deprecated and forward to Workspace.
  3. Choose simulation or query. Do not use .Touched as a universal hit detector. Use a ray for a path/line, an overlap query for a volume, and simulation contacts when physical response is actually required.
  4. Apply motion at assembly level. Forces on a part affect its assembly. Use modern LinearVelocity, AngularVelocity, VectorForce, AlignPosition, and AlignOrientation constraints as appropriate; migrate deprecated BodyMovers when changing that system.
  5. Set ownership deliberately. Server-own gameplay-critical loose assemblies when required; client ownership can improve responsiveness but never authorizes gameplay results.
  6. Bound cost and lifetime. Reuse query parameters, cap query frequency/result count, remove temporary constraints/attachments, and disconnect event listeners.
  7. Verify under load and multiplayer. Test anchored/unanchored transitions, mass extremes, collision matrix, fast motion, multiple clients, ownership changes, streaming, and cleanup.

Pattern: filtered server raycast

local Workspace = game:GetService("Workspace")

local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Exclude
params.FilterDescendantsInstances = {shooterCharacter}
params.IgnoreWater = true
params.CollisionGroup = "WeaponQuery"

local direction = aimDirection.Unit * MAX_RANGE
local result = Workspace:Raycast(muzzlePosition, direction, params)
if result then
    local model = result.Instance:FindFirstAncestorOfClass("Model")
    local humanoid = model and model:FindFirstChildOfClass("Humanoid")
    if humanoid and serverCanDamage(shooter, model, result.Position) then
        humanoid:TakeDamage(serverWeaponDamage(shooter))
    end
end

The server must validate the origin/direction against server-known character/weapon state; do not accept an arbitrary client origin and treat the raycast itself as validation.

Pattern: overlap volume with explicit policy

local params = OverlapParams.new()
params.FilterType = Enum.RaycastFilterType.Exclude
params.FilterDescendantsInstances = {sourceCharacter}
params.CollisionGroup = "DamageQuery"
params.MaxParts = 64

local seen: {[Model]: boolean} = {}
for _, part in Workspace:GetPartBoundsInBox(hitboxCFrame, hitboxSize, params) do
    local model = part:FindFirstAncestorOfClass("Model")
    if model and not seen[model] then
        seen[model] = true
        validateAndApplyHit(model)
    end
end

Bounds queries use bounding boxes and can include multiple parts from one ta

常见问题

为什么不用 Touched 做命中检测?

该技能指出,Touched 可能不可靠,并且容易被利用,因此更推荐服务器射线投射或重叠检查。

它涵盖角色移动吗?

不涵盖。Humanoid 移动由另一份 Roblox 角色技能负责。

它涵盖调整物理手感吗?

只涵盖一部分。与引擎无关的物理调优由另一份物理调优技能负责。

详情

作者的原始描述

Implement Roblox physical simulation and queries with assemblies, anchoring, constraints, collision groups, CanCollide/CanTouch/CanQuery, raycasts and overlap queries, mass, impulses, forces, velocity, moving assemblies, cleanup, and network ownership. Use for Roblox collisions, hit detection, RaycastParams, PhysicsService, projectiles, vehicles, knockback, constraints, deprecated BodyMovers, unstable motion, or client-owned physics exploits.

repo: gamedev-skills/awesome-gamedev-agent-skills

热度

GitHub 星标
6.6k
排名
#13840
许可证
Apache-2.0
更新时间
2026/10/28

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能