roblox-physics
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chineseroblox-physics
roblox-physics
Official sources:
- https://create.roblox.com/docs/physics
- https://create.roblox.com/docs/physics/assemblies
- https://create.roblox.com/docs/physics/mechanical-constraints
- https://create.roblox.com/docs/physics/mover-constraints
- https://create.roblox.com/docs/physics/network-ownership
- https://create.roblox.com/docs/physics/sleep-system
- https://create.roblox.com/docs/physics/adaptive-timestepping
- https://create.roblox.com/docs/physics/units
- https://create.roblox.com/docs/workspace/collisions
Use mechanical constraints to connect parts and mover constraints to apply forces or velocity targets. For older code, use the BodyMover migration table below.
官方资料:
- https://create.roblox.com/docs/physics
- https://create.roblox.com/docs/physics/assemblies
- https://create.roblox.com/docs/physics/mechanical-constraints
- https://create.roblox.com/docs/physics/mover-constraints
- https://create.roblox.com/docs/physics/network-ownership
- https://create.roblox.com/docs/physics/sleep-system
- https://create.roblox.com/docs/physics/adaptive-timestepping
- https://create.roblox.com/docs/physics/units
- https://create.roblox.com/docs/workspace/collisions
使用机械约束连接部件,并使用 Mover 约束施力或设置速度目标。对于旧版代码,请使用下方的 BodyMover 迁移对照表。
Core concepts
核心概念
Assemblies
装配体
An assembly is one or more parts connected by rigid welds or movable joints, simulated as a single rigid body.
Key properties (same for any part in the assembly):
BasePart- /
AssemblyLinearVelocity: prefer constraints orAssemblyAngularVelocityover direct assignment for realistic motion.ApplyImpulse - : force here produces pure linear acceleration.
AssemblyCenterOfMass - : sum of all part masses; infinite if any part is anchored.
AssemblyMass - : automatically chosen root for replication and network ownership.
AssemblyRootPart
Root-part priority: anchored > non-massless > higher > size/name heuristics.
RootPriority装配体是由刚性焊接或可移动关节连接的一个或多个部件,作为一个刚性物体进行仿真。
关键 属性(装配体中的任意部件均适用):
BasePart- /
AssemblyLinearVelocity:为获得更真实的运动,应优先使用约束或AssemblyAngularVelocity,而不是直接赋值。ApplyImpulse - :在此处施力会产生纯线性加速度。
AssemblyCenterOfMass - :所有部件质量的总和;如果任何部件已固定,则为无穷大。
AssemblyMass - :自动选作复制和网络所有权根部件。
AssemblyRootPart
根部件优先级:已固定 > 非零质量 > 更高的 > 尺寸/名称启发式规则。
RootPriorityAnchoring
固定
- Anchoring one part in an assembly makes it the root; the rest are implicitly anchored.
- Anchoring multiple parts in the same assembly splits it.
- To anchor an entire assembly, only anchor the root part.
- 固定装配体中的一个部件会使其成为根部件;其余部件也会被隐式固定。
- 固定同一装配体中的多个部件会将其拆分。
- 要固定整个装配体,只需固定根部件。
Collision filtering
碰撞过滤
Use collision groups ( (inherited from ), ) or for part-to-part filtering. , , and control different behaviors; see references/collisions-and-filtering.md.
Workspace:RegisterCollisionGroupWorldRootBasePart.CollisionGroupNoCollisionConstraintCanCollideCanTouchCanQuery使用碰撞组(,继承自 ;以及 )或 进行部件之间的过滤。、 和 分别控制不同的行为;参见 references/collisions-and-filtering.md。
Workspace:RegisterCollisionGroupWorldRootBasePart.CollisionGroupNoCollisionConstraintCanCollideCanTouchCanQueryMechanical constraints
机械约束
All mechanical constraints connect one or two s (or s), except and which use /.
AttachmentBoneWeldConstraintNoCollisionConstraintPart0Part1| Constraint | Use case |
|---|---|
| Rigidly lock two parts together, same relative transform |
| Same as WeldConstraint but attachment-based, supports bones |
| Doors, levers, rotating parts; motor/servo optional |
| Sliding doors, elevators, pistons |
| Slides + rotates, like hydraulic rams or landing gear |
| Springs, shocks, suspension |
| Rotational springs |
| Shoulders, ball joints |
| Drive shafts, constant-velocity joints |
| Cables, winches, maximum length |
| Fixed separation distance |
| Constrain motion to a plane |
| Disable collisions between two specific parts |
See references/mechanical-constraints.md for creation, orientation, motor/servo tuning, and limits.
除 和 使用 / 外,所有机械约束都可连接一个或两个 (或 )。
WeldConstraintNoCollisionConstraintPart0Part1AttachmentBone| 约束 | 用途 |
|---|---|
| 将两个部件刚性锁定在一起,保持相同的相对变换 |
| 与 WeldConstraint 相同,但基于 attachment,并支持 bone |
| 门、杠杆、旋转部件;可选用 motor/servo |
| 滑动门、电梯、活塞 |
| 兼具滑动和旋转,如液压缸或起落架 |
| 弹簧、减震器、悬挂 |
| 旋转弹簧 |
| 肩部、球形接头 |
| 驱动轴、等速接头 |
| 缆绳、绞盘、最大长度 |
| 固定分离距离 |
| 将运动约束在平面内 |
| 禁用两个特定部件之间的碰撞 |
有关创建方式、方向、motor/servo 调优和限位设置,请参见 references/mechanical-constraints.md。
Mover constraints
Mover 约束
Modern replacements for deprecated s:
BodyMover| Legacy | Modern | Use case |
|---|---|---|
| | Move attachment to a position or another attachment |
| | Align orientation; |
| | Maintain constant velocity along vector/line/plane |
| | Maintain constant angular velocity |
| | Apply constant force |
| | Follow + face target |
| - | | Apply constant torque |
| - | | Force along line between two attachments |
| - | | Constraint driven by animation/transform |
See references/mover-constraints.md for force modes ( vs ), relativity frames, rigidity, and reaction forces.
MagnitudePerAxis已弃用 的现代替代方案:
BodyMover| 旧版 | 现代替代方案 | 用途 |
|---|---|---|
| | 将 attachment 移动到某个位置或另一个 attachment |
| | 对齐朝向;使用 |
| | 沿向量、直线或平面保持恒定速度 |
| | 保持恒定角速度 |
| | 施加恒定力 |
| | 跟随并朝向目标 |
| - | | 施加恒定扭矩 |
| - | | 沿两个 attachment 之间的直线施力 |
| - | | 由动画/变换驱动的约束 |
有关力模式( 与 )、相对参考系、刚度和反作用力,请参见 references/mover-constraints.md。
MagnitudePerAxisNetwork ownership
网络所有权
- The server owns anchored parts.
- Unanchored parts near a player character are automatically owned by that client.
- Set ownership explicitly with (server only). Reset with
BasePart:SetNetworkOwner(player).SetNetworkOwnershipAuto() - Assign vehicle/driver ownership carefully: the first seated player may own the whole assembly otherwise.
Security: clients can exploit owned parts (teleport, fake collisions). Validate gameplay-critical events server-side. See references/network-ownership.md.
- 已固定部件归服务器所有。
- 靠近玩家角色的未固定部件会自动归该客户端所有。
- 使用 显式设置所有权(仅限服务器)。使用
BasePart:SetNetworkOwner(player)重置。SetNetworkOwnershipAuto() - 为载具/驾驶员分配所有权时要格外谨慎;否则,第一个坐入的玩家可能会拥有整个装配体。
**安全性:**客户端可以利用其拥有的部件作弊(传送、伪造碰撞)。应在服务端验证与玩法相关的重要事件。参见 references/network-ownership.md。
Sleep system
休眠系统
Assemblies stop simulating when still to save performance. They wake on collisions, property changes, impulses, or gravity/wind changes.
- If a slow mechanism falls asleep, increase motion or use actuated joints (motor/servo constraints) which get stricter sleep thresholds.
- Visualize sleep states with Awake parts in Studio's Visualization Options.
装配体静止时会停止仿真,以节省性能。它们会在发生碰撞、属性变化、受到冲量或重力/风力变化时唤醒。
- 如果缓慢运动的机制提前进入休眠,请增加运动量,或使用驱动关节(motor/servo 约束),这类关节采用更严格的休眠阈值。
- 可通过 Studio 的 Visualization Options 中的 Awake parts 将休眠状态可视化。
Physics stepping method
物理步进方法
Workspace.PhysicsSteppingMethod:
- Fixed (default, 240 Hz): best general choice; use for racing, destruction, tanks, or when most parts already solve at 240 Hz.
- Adaptive: assigns assemblies to 60/120/240 Hz islands for up to ~2.5× performance in suitable experiences.
Use the MicroProfiler to check island distribution.
Workspace.PhysicsSteppingMethod- Fixed(默认,240 Hz):通用场景的最佳选择;适用于竞速、破坏、坦克,或大多数部件已经能够以 240 Hz 求解时。
- Adaptive:将装配体分配到 60/120/240 Hz 岛,在合适的项目中最多可提升约 2.5× 性能。
使用 MicroProfiler 检查各岛的分布。
Units quick reference
单位速查
| Roblox | Metric |
|---|---|
| 1 stud | 28 cm |
| 1 RMU | 21.952 kg |
| 196.2 studs/s² | default "Classic" gravity |
| 35 studs/s² | "Realistic" gravity (≈ 9.8 m/s²) |
See references/units-and-physical-properties.md.
| Roblox | 公制 |
|---|---|
| 1 stud | 28 cm |
| 1 RMU | 21.952 kg |
| 196.2 studs/s² | 默认的 "Classic" 重力 |
| 35 studs/s² | "Realistic" 重力(≈ 9.8 m/s²) |
参见 references/units-and-physical-properties.md。
Common mistakes
常见错误
- Using deprecated s instead of modern constraints.
BodyMover - Setting every frame instead of using forces/constraints.
CFrame - Anchoring every part in an assembly (splits it and hurts performance).
- Ignoring network ownership on vehicles and then wondering why input lags.
- Trusting events from client-owned parts for damage/authority.
Touched - Letting actuated joints fall asleep prematurely.
- 使用已弃用的 ,而不是现代约束。
BodyMover - 每帧直接设置 ,而不是使用力/约束。
CFrame - 固定装配体中的每个部件(这会拆分装配体并损害性能)。
- 忽略载具的网络所有权,随后又疑惑为何输入延迟。
- 信任客户端拥有的部件触发的 事件来处理伤害或权威判定。
Touched - 让驱动关节过早进入休眠。
Scripts
脚本
- : chassis setup with
scripts/VehicleController.luasteering and motor drive, with client ownership and server validation.HingeConstraint - : motorized/servo door with limits and state machine.
scripts/DoorHinge.lua - :
scripts/PlatformMover.lua+AlignPositionplatform with configurable waypoints.AlignOrientation - : spring-damper suspension using
scripts/Suspension.lua.SpringConstraint
- :使用
scripts/VehicleController.lua实现转向和电机驱动的底盘配置,并包含客户端所有权及服务端验证。HingeConstraint - :带限位和状态机的电机/伺服门。
scripts/DoorHinge.lua - :使用
scripts/PlatformMover.lua+AlignPosition的平台,可配置路径点。AlignOrientation - :使用
scripts/Suspension.lua实现的弹簧-阻尼悬挂系统。SpringConstraint
How to proceed
操作步骤
- Decide if the object is a rigid mechanism (mechanical constraint) or force-driven (mover constraint).
- Plan assemblies, root parts, and anchoring strategy.
- Set network ownership for multiplayer responsiveness.
- Tune forces/velocities using units and physical properties.
- Profile with MicroProfiler and watch sleep/ownership visualizations.
- 确定对象应采用刚性机械装置(mechanical constraint)还是力驱动方式(mover constraint)。
- 规划装配体、根部件和固定策略。
- 设置网络所有权,以提升多人游戏的响应速度。
- 使用单位和物理属性调优力/速度。
- 使用 MicroProfiler 进行性能分析,并观察休眠/所有权可视化。
Reference index
参考索引
- collisions-and-filtering.md: Configure collision groups, touch events, or spatial query filters.
- mechanical-constraints.md: Connect parts with hinges, springs, ropes, or other mechanical constraints.
- mover-constraints.md: Apply forces or velocity targets, or migrate BodyMover code.
- network-ownership.md: Assign physics simulation to the server or a player and debug ownership.
- units-and-physical-properties.md: Tune mass, density, friction, force, or simulation stepping.
- collisions-and-filtering.md:配置碰撞组、触摸事件或空间查询过滤器。
- mechanical-constraints.md:使用铰链、弹簧、绳索或其他机械约束连接部件。
- mover-constraints.md:施力或设置速度目标,以及迁移 BodyMover 代码。
- network-ownership.md:将物理仿真分配给服务器或玩家,并排查所有权问题。
- units-and-physical-properties.md:调整质量、密度、摩擦力、力或仿真步进。