roblox-physics

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

roblox-physics

roblox-physics

Core concepts

核心概念

Assemblies

装配体

An assembly is one or more parts connected by rigid welds or movable joints, simulated as a single rigid body.
Key
BasePart
properties (same for any part in the assembly):
  • AssemblyLinearVelocity
    /
    AssemblyAngularVelocity
    : prefer constraints or
    ApplyImpulse
    over direct assignment for realistic motion.
  • AssemblyCenterOfMass
    : force here produces pure linear acceleration.
  • AssemblyMass
    : sum of all part masses; infinite if any part is anchored.
  • AssemblyRootPart
    : automatically chosen root for replication and network ownership.
Root-part priority: anchored > non-massless > higher
RootPriority
> size/name heuristics.
装配体是由刚性焊接或可移动关节连接的一个或多个部件,作为一个刚性物体进行仿真。
关键
BasePart
属性(装配体中的任意部件均适用):
  • AssemblyLinearVelocity
    /
    AssemblyAngularVelocity
    :为获得更真实的运动,应优先使用约束或
    ApplyImpulse
    ,而不是直接赋值。
  • AssemblyCenterOfMass
    :在此处施力会产生纯线性加速度。
  • AssemblyMass
    :所有部件质量的总和;如果任何部件已固定,则为无穷大。
  • AssemblyRootPart
    :自动选作复制和网络所有权根部件。
根部件优先级:已固定 > 非零质量 > 更高的
RootPriority
> 尺寸/名称启发式规则。

Anchoring

固定

  • 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 (
Workspace:RegisterCollisionGroup
(inherited from
WorldRoot
),
BasePart.CollisionGroup
) or
NoCollisionConstraint
for part-to-part filtering.
CanCollide
,
CanTouch
, and
CanQuery
control different behaviors; see references/collisions-and-filtering.md.
使用碰撞组(
Workspace:RegisterCollisionGroup
,继承自
WorldRoot
;以及
BasePart.CollisionGroup
)或
NoCollisionConstraint
进行部件之间的过滤。
CanCollide
、
CanTouch
和
CanQuery
分别控制不同的行为;参见 references/collisions-and-filtering.md。

Mechanical constraints

机械约束

All mechanical constraints connect one or two
Attachment
s (or
Bone
s), except
WeldConstraint
and
NoCollisionConstraint
which use
Part0
/
Part1
.
ConstraintUse case
WeldConstraint
Rigidly lock two parts together, same relative transform
RigidConstraint
Same as WeldConstraint but attachment-based, supports bones
HingeConstraint
Doors, levers, rotating parts; motor/servo optional
PrismaticConstraint
Sliding doors, elevators, pistons
CylindricalConstraint
Slides + rotates, like hydraulic rams or landing gear
SpringConstraint
Springs, shocks, suspension
TorsionSpringConstraint
Rotational springs
BallSocketConstraint
Shoulders, ball joints
UniversalConstraint
Drive shafts, constant-velocity joints
RopeConstraint
Cables, winches, maximum length
RodConstraint
Fixed separation distance
PlaneConstraint
Constrain motion to a plane
NoCollisionConstraint
Disable collisions between two specific parts
See references/mechanical-constraints.md for creation, orientation, motor/servo tuning, and limits.
除
WeldConstraint
和
NoCollisionConstraint
使用
Part0
/
Part1
外,所有机械约束都可连接一个或两个
Attachment
(或
Bone
)。
约束用途
WeldConstraint
将两个部件刚性锁定在一起,保持相同的相对变换
RigidConstraint
与 WeldConstraint 相同,但基于 attachment,并支持 bone
HingeConstraint
门、杠杆、旋转部件;可选用 motor/servo
PrismaticConstraint
滑动门、电梯、活塞
CylindricalConstraint
兼具滑动和旋转,如液压缸或起落架
SpringConstraint
弹簧、减震器、悬挂
TorsionSpringConstraint
旋转弹簧
BallSocketConstraint
肩部、球形接头
UniversalConstraint
驱动轴、等速接头
RopeConstraint
缆绳、绞盘、最大长度
RodConstraint
固定分离距离
PlaneConstraint
将运动约束在平面内
NoCollisionConstraint
禁用两个特定部件之间的碰撞
有关创建方式、方向、motor/servo 调优和限位设置,请参见 references/mechanical-constraints.md。

Mover constraints

Mover 约束

Modern replacements for deprecated
BodyMover
s:
LegacyModernUse case
BodyPosition
AlignPosition
Move attachment to a position or another attachment
BodyGyro
AlignOrientation
Align orientation;
LookAtPosition
for tracking
BodyVelocity
LinearVelocity
Maintain constant velocity along vector/line/plane
BodyAngularVelocity
AngularVelocity
Maintain constant angular velocity
BodyForce
/
BodyThrust
VectorForce
Apply constant force
RocketPropulsion
LineForce
+
AlignOrientation
Follow + face target
-
Torque
Apply constant torque
-
LineForce
Force along line between two attachments
-
AnimationConstraint
Constraint driven by animation/transform
See references/mover-constraints.md for force modes (
Magnitude
vs
PerAxis
), relativity frames, rigidity, and reaction forces.
已弃用
BodyMover
的现代替代方案:
旧版现代替代方案用途
BodyPosition
AlignPosition
将 attachment 移动到某个位置或另一个 attachment
BodyGyro
AlignOrientation
对齐朝向;使用
LookAtPosition
进行追踪
BodyVelocity
LinearVelocity
沿向量、直线或平面保持恒定速度
BodyAngularVelocity
AngularVelocity
保持恒定角速度
BodyForce
/
BodyThrust
VectorForce
施加恒定力
RocketPropulsion
LineForce
+
AlignOrientation
跟随并朝向目标
-
Torque
施加恒定扭矩
-
LineForce
沿两个 attachment 之间的直线施力
-
AnimationConstraint
由动画/变换驱动的约束
有关力模式(
Magnitude
与
PerAxis
)、相对参考系、刚度和反作用力,请参见 references/mover-constraints.md。

Network ownership

网络所有权

  • The server owns anchored parts.
  • Unanchored parts near a player character are automatically owned by that client.
  • Set ownership explicitly with
    BasePart:SetNetworkOwner(player)
    (server only). Reset with
    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

单位速查

RobloxMetric
1 stud28 cm
1 RMU21.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 stud28 cm
1 RMU21.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
    BodyMover
    s instead of modern constraints.
  • Setting
    CFrame
    every frame instead of using forces/constraints.
  • Anchoring every part in an assembly (splits it and hurts performance).
  • Ignoring network ownership on vehicles and then wondering why input lags.
  • Trusting
    Touched
    events from client-owned parts for damage/authority.
  • Letting actuated joints fall asleep prematurely.
  • 使用已弃用的
    BodyMover
    ,而不是现代约束。
  • 每帧直接设置
    CFrame
    ,而不是使用力/约束。
  • 固定装配体中的每个部件(这会拆分装配体并损害性能)。
  • 忽略载具的网络所有权,随后又疑惑为何输入延迟。
  • 信任客户端拥有的部件触发的
    Touched
    事件来处理伤害或权威判定。
  • 让驱动关节过早进入休眠。

Scripts

脚本

  • scripts/VehicleController.lua
    : chassis setup with
    HingeConstraint
    steering and motor drive, with client ownership and server validation.
  • scripts/DoorHinge.lua
    : motorized/servo door with limits and state machine.
  • scripts/PlatformMover.lua
    :
    AlignPosition
    +
    AlignOrientation
    platform with configurable waypoints.
  • scripts/Suspension.lua
    : spring-damper suspension using
    SpringConstraint
    .
  • scripts/VehicleController.lua
    :使用
    HingeConstraint
    实现转向和电机驱动的底盘配置,并包含客户端所有权及服务端验证。
  • scripts/DoorHinge.lua
    :带限位和状态机的电机/伺服门。
  • scripts/PlatformMover.lua
    :使用
    AlignPosition
    +
    AlignOrientation
    的平台,可配置路径点。
  • scripts/Suspension.lua
    :使用
    SpringConstraint
    实现的弹簧-阻尼悬挂系统。

How to proceed

操作步骤

  1. Decide if the object is a rigid mechanism (mechanical constraint) or force-driven (mover constraint).
  2. Plan assemblies, root parts, and anchoring strategy.
  3. Set network ownership for multiplayer responsiveness.
  4. Tune forces/velocities using units and physical properties.
  5. Profile with MicroProfiler and watch sleep/ownership visualizations.
<!-- catalog:references:start -->
  1. 确定对象应采用刚性机械装置(mechanical constraint)还是力驱动方式(mover constraint)。
  2. 规划装配体、根部件和固定策略。
  3. 设置网络所有权,以提升多人游戏的响应速度。
  4. 使用单位和物理属性调优力/速度。
  5. 使用 MicroProfiler 进行性能分析,并观察休眠/所有权可视化。
<!-- catalog:references:start -->

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.
<!-- catalog:references:end -->
  • collisions-and-filtering.md:配置碰撞组、触摸事件或空间查询过滤器。
  • mechanical-constraints.md:使用铰链、弹簧、绳索或其他机械约束连接部件。
  • mover-constraints.md:施力或设置速度目标,以及迁移 BodyMover 代码。
  • network-ownership.md:将物理仿真分配给服务器或玩家,并排查所有权问题。
  • units-and-physical-properties.md:调整质量、密度、摩擦力、力或仿真步进。
<!-- catalog:references:end -->