运动模型Movement Model
依据运动相关源码(Move.h / Avoidance.h / Traffic.h) · 插图为示意图Based on the movement sources (Move.h / Avoidance.h / Traffic.h) · diagrams are schematic
概述 Overview
Mass Battle 的每个单位每 tick 走一条四层管线:① 期望速度——寻路给出方向,乘上单位移速得到"我想怎么走"(意图);② 交通偏置——一套交通规则在远场把意图改写成"按让行文化该怎么走"(车道、侧让、绕行、贴墙);③ 避障解算——ORCA 速度空间求解器在近场算出"不撞人的可行速度"(主动避障);④ 碰撞修正——PBD 作为最后防线,把已经穿透的身体分开(被动碰撞)。前三层只生产速度,第四层只修正位置——职责单一、逐层兜底。
Every Mass Battle unit walks a four-layer pipeline each tick: ① Desired velocity — pathfinding supplies the direction, multiplied by the unit's move speed ("where I want to go" — intent); ② Traffic bias — a rule set rewrites that intent at long range into "how the traffic culture says to go" (lanes, side-stepping, flanking, wall-sliding); ③ Avoidance solve — the ORCA velocity-space solver computes a collision-free feasible speed at short range (active avoidance); ④ Collision correction — PBD is the last line of defense, separating already-overlapping bodies (passive collision). The first three layers only produce velocity; the fourth only corrects position — single responsibilities, layered fallbacks.
交通规则在远处起作用(决定"谁让、怎么让"),避障求解在近处起作用(保证不撞人),碰撞修正是底线(万一穿透必被分开)。"谁让"的判定只做一次,两层共用——所以你不会看到两个单位因为"该你让/该我让"判定不一致而顶牛。
Traffic rules act at range (deciding "who yields and how"), the avoidance solve acts up close (guaranteeing no collisions), and collision correction is the floor (any overlap gets separated). "Who yields" is decided once and shared by both layers — you never see two units deadlock over disagreeing responsibility.
分层管线总图 The Layered Pipeline
移动在每帧模拟的最后阶段执行,因此击退、发射等施加会在同一逻辑帧内生效。四个层次从上到下依次是:先算出"我想怎么走"(期望速度),再按让行惯例改写它(交通偏置),然后解出"不撞人的最近速度"(避障),最后修正穿透(碰撞):
Movement runs in the final stage of each simulation frame, so knockback and launches land within the same logic tick. The four layers run top to bottom: first "where I want to go" (desired velocity), then the yielding conventions rewrite it (traffic bias), then the solver picks the nearest collision-free speed (avoidance), and finally any penetration is corrected (collision):
① 期望速度层 Layer 1 — Desired Velocity
意图 = 方向 × 速度。方向来自寻路,按导航模式三选一:流场跟随(人群共享方向)、A* 路径(单体路径,目标移动时只打补丁、不全量重算)、直线。攻击瞄准、坠落、发射、濒死时寻路整体暂停。速度由六个配置项连乘决定,再经 XYSpeedLimit 钳制——每一项都在兵种 DataAsset 里可调:
Intent = direction × speed. Direction comes from pathfinding, one of three modes: flow-field following (crowd-shared), A* polyline (per-unit paths; a moving goal gets a patch, not a full recalc), or straight line. Aiming, falling, launching and dying pause pathfinding entirely. Speed is the product of six configurable factors, clamped by XYSpeedLimit — every one lives in the unit DataAsset:
行为倍率Behavior multiplier
按 ActiveBehavior 取 Patrol / Chase / Return 的 MoveSpeedMult,Idle 默认 1.0。
Takes Patrol / Chase / Return MoveSpeedMult by ActiveBehavior; Idle defaults to 1.0.
减速 debuffSlow debuffs
多个 SlowDebuff 取最大强度;CombinedSlowMult = lerp(1−强度, 1, 慢免疫)。
Takes the max strength among SlowDebuffs; CombinedSlowMult = lerp(1−strength, 1, slow immunity).
出生变异Spawn variation
出生时从随机流掷出的 FMoving.MoveSpeedMult——同种单位速度有个体差异。
FMoving.MoveSpeedMult rolled from the spawn-time random stream — per-individual speed variety.
转角映射(生物模型)Turn-angle map (Creature)
朝向与速度夹角经 MoveSpeedRangeMapByAngle 映射——急转弯自动掉速。
The heading–velocity angle maps through MoveSpeedRangeMapByAngle — sharp turns automatically shed speed.
距离坡化Distance ramp
距目标距离经 MoveSpeedRangeMapByDist 二次插值——临抵达自然减速到零。
Distance-to-goal maps through a quadratic MoveSpeedRangeMapByDist — natural deceleration into arrival.
坡度恒速Slope constant-speed
bMaintainConstantSpeedOnSlope 时按地面法线在前进方向的分量除回去——上下坡视觉等速。
With bMaintainConstantSpeedOnSlope the ground-normal component along travel is divided out — visually constant speed on slopes.
接近目标时,单位按自身刹车距离自然减停,不会在终点附近来回抖动。玩家驱动的单位不走这条链——它们的期望速度直接来自玩家输入。
Approaching the goal, units decelerate naturally to a stop based on their own braking distance — no jitter around the destination. Player-driven units bypass the chain — their desired velocity comes straight from player input.
② 交通偏置层 Layer 2 — Traffic Bias
交通层在避障求解之前,把期望速度改写成符合让行惯例的方向——车道化、给通行者让位、绕开挡路者、贴墙滑行。全局总闸 FAvoidance::bUseTrafficRules 默认关闭;打开后由模板上的 FTrafficShared 逐规则配置(Arbitration / Flank / LaneShift / SideStep / WallSlide 与 Combat 路权默认开,LivingVsDying 与 Pressure 默认关)。
The traffic layer rewrites the desired velocity toward yielding conventions before the avoidance solve — lane formation, yielding the corridor, flanking blockers, wall sliding. The master gate FAvoidance::bUseTrafficRules defaults OFF; once on, each rule is configured per template via FTrafficShared (Arbitration / Flank / LaneShift / SideStep / WallSlide and Combat right-of-way default ON; LivingVsDying and Pressure default OFF).
LaneShift 车道偏移 LaneShift
对向人流会自发分成两条车道:移动中的单位把前进方向从来车方向旋开、向行进侧约定(默认靠右)偏转;交叉的两股人流各让己侧,自然涌现真实人群里的对角条纹。每个对头邻居贡献的旋转角、总量上限、判侧死区带宽与交叉带扩展都是可调参数,判侧死区防止单位逐帧换边抖动。
Oncoming streams self-organize into two lanes: moving units rotate their heading away from oncoming traffic toward the traffic-side convention (drive-on-the-right by default); crossing streams each yield to their own side, self-organizing into the diagonal stripes seen in real crowds. Per-neighbor rotation, the total cap, the side-pick dead-zone band and the crossing-band extension are all tunable; the dead zone prevents frame-by-frame side flipping.
SideStep 侧让 SideStep
静止单位面对来袭者会主动侧身让出通道,而不是被推着走:让多少由对方体型与实际净空缺口决定——步兵路过人群几乎不动它,坦克路过会让出整条通道。让出时间、净空余量与强度可调;追击锁定中的单位会站定不让(优先输出)。
Idle units step aside for oncoming traffic instead of being shoved along: how far they step follows the passer's size and the actual clearance deficit — infantry passing a crowd barely nudge it, a tank gets a whole lane. Step time, clearance margin and strength are tunable; units locked on a chase stand their ground (output first).
Flank 绕行 Flank
被挡住去路的单位会绕行:把前进方向旋出阻挡者的影响锥,以接近全速绕过挡路者(绕行期间有配套提速);能倒车的载具甚至可以倒着完成绕行。相邻阻挡者之间的缝隙,只有宽于"自身直径 + 余量"才会钻,否则整簇绕开——不硬挤。紧贴障碍物时本规则自动让位给避障层。
Blocked units flank: they rotate their heading out of the blockers' influence cone and pass at near full speed (with a paired speed boost while flanking); vehicles that can reverse may flank in reverse. A gap between adjacent blockers is threaded only if it is wider than "own diameter + margin" — otherwise the whole cluster is skirted, never squeezed through. Right against obstacles the rule yields to the avoidance layer.
WallSlide 贴墙滑行 WallSlide
带着朝墙分量的移动会被剥掉向内分量,转为沿墙切线滑行;强度从接触带(纯滑行)到避障外缘(不受影响)渐变。不做额外减速——剥掉向内分量本身就是自然的减速,自然的贴墙滑走观感由此而来。
Movement with a component into a wall gets that inward component stripped, turning into a slide along the wall tangent; strength ramps from the contact band (pure slide) to the avoidance rim (untouched). No extra braking — stripping the inward component IS the deceleration, producing the natural wall-slide look.
Arbitration 责任仲裁 Arbitration — who yields
谁让、让多少,由一组明确的惯例决定:不可让的一方(站定的攻击者、不可推动物)→ 对方全让;路权档位不同 → 低档位多让(档位从高到低:攻击者 > 远程归位 > 移动中 > 归位中 > 空闲);同档对头 → 各让一半;追尾 → 后车让;轻者让重者(按质量比分配)。攻击者在瞄准/前摇/后摇阶段钉在原地,其他单位绕行。让步比例(YieldBias)、行进侧约定与质量加权都有全局配置。
Who yields and how much follows explicit conventions: a side that cannot yield (a planted attacker, an immovable) forces the other side to fully yield; right-of-way rank asymmetry → the lower rank yields more (ranks high to low: attacker > far-returner > moving > returning > idle); equal head-on → 50/50; rear-ending → the rear yields; the lighter yields to the heavier (by mass ratio). Attackers plant their feet through aim / wind-up / recovery while everyone routes around them. The yield share (YieldBias), traffic-side convention and mass weighting are global knobs.
另有两条按需开启的规则:LivingVsDying(默认关)——濒死的身体可以被穿行,倒地不再堵路(与死亡单位的碰撞另有开关);Pressure(默认关)——解算后向人群稀疏的方向再偏一步,缓解极端密集(灵敏度与上限可调)。
Two more rules open on demand: LivingVsDying (default OFF) — dying bodies can be walked through as they fall, so corpses stop clogging lanes (collision with the dying has its own toggle); Pressure (default OFF) — after the solve, velocity nudges one step toward sparser areas to relieve extreme crowding (sensitivity and cap configurable).
③ 避障解算层 Layer 3 — The Avoidance Solve (ORCA)
避障层在近场自动解出"不撞人的最近速度":每个会碰撞的邻居产生一条约束,"让多少"按上面的责任判定分配,最终取距期望速度最近的可行速度。它只管近距离防穿插,不会在远处提前减速(反应距离有封顶倍率可调);被围死时能找回掉速,轻单位顶不动重单位时会放弃推挤、改走人流。求解器可在 ORCA 与斥力场之间切换(AvoidMethod),后者参数更少、观感更松。
The avoidance layer automatically solves for the nearest collision-free speed up close: every colliding neighbor contributes a constraint, "how much to give" follows the responsibility verdicts above, and the solver picks the feasible speed closest to the desired one. It only prevents penetration at short range and never decelerates early at distance (the reaction range has a tunable cap multiplier); boxed-in units recover lost speed, and a light unit that cannot push a heavy one gives up and flows through instead. The solver switches between ORCA and a repulsion field (AvoidMethod) — fewer knobs, a looser feel.
CrushRecover 挤压回升CrushRecover
被四面围死时,朝阻挡最小的方向找回掉速——密集包围不会永久锁死单位。
Boxed in on all sides, a unit recovers lost speed toward the least-blocked direction — dense encirclement never permanently locks it.
突破回落 BreakthroughBreakthrough fallback
轻单位顶不动重单位时,放弃推挤、直接"穿流"而过——穿透由碰撞层收拾。
When a light unit cannot push a heavy one, it stops shoving and flows through — the collision layer cleans up the penetration.
ForceField 备选求解器ForceField solver
AvoidMethod 可切换为斥力场模型:邻居按距离产生斥力叠加(Strength / SepSpeedCapFraction / VelocityDamping),同样消费交通层偏置与 yield。
AvoidMethod can switch to a repulsion-field model: neighbors add distance-scaled repulsive forces (Strength / SepSpeedCapFraction / VelocityDamping), consuming the same traffic biases and yields.
④ 碰撞修正层 Layer 4 — Collision Correction (PBD)
碰撞层是最后防线:速度解算与位置推进之后,任何已经发生的穿透都会被当场分开。优先级清晰:墙、地面、天花板的穿透当帧弹回,单位绝不穿墙;单位之间的推挤按质量反比分配(重者少动、不可推动者不动);站定的单位(瞄准中的攻击者、静置单位)不会被推离原地。修正会以符合自身加/减速度节奏的方式回馈到速度,不会瞬移。
The collision layer is the last line of defense: after velocities resolve and positions advance, any penetration that already happened is separated on the spot. Priorities are clear: wall / ground / ceiling penetrations pop back the same frame — units never tunnel through walls; inter-unit pushes split by inverse mass (the heavy barely moves, the immovable not at all); planted units (aiming attackers, idle ones) are not shoved off their spot. Corrections feed back into velocity at the unit's own acceleration / deceleration pace — no teleporting.
Substeps 配置(默认 1)大于 1 时,碰撞改由独立的多子步解算器执行:解算更稳,极端堆叠(万人挤作一团)场景下的表现更好;MassBattle.Physics.DebugResidual 1 可以把收敛过程可视化出来。
With Substeps above 1 (default 1), collision moves to a standalone multi-substep solver: steadier solves and better behavior under extreme stacking (ten-thousand-agent pileups); MassBattle.Physics.DebugResidual 1 visualizes the convergence.
四层协作总表 How the Four Layers Cooperate
| 层Layer | 职责一句话One-line duty | 输入 → 输出Input → output | 作用距离Range | 改什么Touches |
|---|---|---|---|---|
| ① 期望速度Desired velocity | 我想怎么走(寻路方向 × 移速链)Where I want to go (path dir × speed chain) | 目标/路径/行为 → 意图速度Goal/path/behavior → intent velocity | 全图Global | 速度Velocity |
| ② 交通偏置Traffic bias | 按让行文化改写意图(车道/侧让/绕行/贴墙)Rewrite intent per traffic culture (lanes/step/flank/slide) | 意图速度 → 让行后速度intent → post-yield velocity | 视野范围内Within vision range | 速度(意图)Velocity (intent) |
| ③ 避障解算Avoidance solve | 不撞人的最近可行速度(ORCA)Nearest collision-free feasible speed (ORCA) | 让行后速度 + 邻居 → 避让速度post-yield velocity + neighbors → avoidance velocity | 近场Close range | 速度Velocity |
| ④ 碰撞修正Collision correction | 穿透必被分开(场景硬约束绝对优先)Penetration always separated (scene hard constraints first) | 位置(穿透) → 位置修正 + 速度回馈Position (overlap) → positional fix + velocity feedback | 接触Contact | 位置(+速度回馈)Position (+ velocity feedback) |
配置速查 Configuration Quick Reference
| 配置Config | 默认Default | 含义Meaning |
|---|---|---|
FAvoidance::bUseTrafficRules | false | 交通层总闸;打开后 FTrafficShared 各规则按自身开关生效Traffic master gate; once on, per-rule toggles inside FTrafficShared apply |
FAvoidance::DetectRange_Agent | — | 单位检测距离扩展量 = 身体半径 + Clamp(TimeHorizon×速度, Min, Max);同时钳制交通视野Agent detection extension = body radius + Clamp(TimeHorizon×speed, Min, Max); also floors the traffic view |
FAvoidance::BrakingRangeMult | — | 求解器反应半径封顶倍率——阻止 ORCA 远距提前减速Solver reaction-radius cap multiplier — stops ORCA from slowing early at range |
Arbitration.YieldBias / TrafficSide / CommitBand / MassWeighting | 0.8 / Right / 0 / 1 | 让步比例 · 行进侧约定 · 判侧滞回带 · 全局质量加权Yield share · traffic-side convention · side-pick hysteresis band · global mass weighting |
LaneShift.PerNeighborDeg / MaxDeg / CrossShift | — / — / on | 每对头邻居旋转角 · 总封顶 · 交叉带扩展Per-head-on-neighbor rotation · total cap · crossing-band extension |
SideStep.Strength / ClearanceMargin / ClearanceTime | 1.0 / — / — | 侧让强度 · 净空余量 · 让出时间折算Step strength · clearance margin · step-time conversion |
Flank.PerBlockerAngle / MaxDeflect / MinGapWidth / SpeedMult / BlockerSpeedRatio | — | 每阻挡角 · 总旋封顶 · 缝宽门 · 绕行提速 · 低速同向阻挡阈值Per-blocker angle · rotation cap · gap gate · flank speed multiplier · slow-blocker threshold |
Combat.RightOfWay / SkipAvoidance | on / on | 攻击者路权(钉地)· 瞄准阶段跳过整套避障Attacker right of way (planted) · aim phases skip the whole solver |
FPhysics::PositionRelaxation_Agent / VelocityRelaxation_Agent / StaticFriction_* | 1.0 / — / — | 位置修正刚度 · 速度回馈系数 · 横/纵向静摩擦预算Position-correction stiffness · velocity-feedback coefficient · lateral/longitudinal static-friction budgets |
MassBattle.Physics.Substeps | 1 | 1 = MoveProcessor 内联单遍;>1 启用独立多子步 PBD 引擎1 = inline single pass inside MoveProcessor; >1 arms the standalone multi-substep PBD engine |
Move.XY.MoveSpeed / MoveAcceleration / MoveDeceleration / MinInitSpeed | — | 基础移速与趋近节奏;MinInitSpeed 以下求解输出直接归零(防抖动)Base speed and approach pacing; solver output below MinInitSpeed zeroes out (anti-jitter) |
深入配置:Move.h · Avoidance.h · Traffic.h(规则参数)与 MassBattleAgentConfigDataAsset(兵种资产)。
Go deeper on configuration: Move.h · Avoidance.h · Traffic.h (rule parameters) and MassBattleAgentConfigDataAsset (the unit asset).