Aim.h
Source/MassBattle/Public/Fragments/Aim.h
概述Overview
瞄准关节的全部配置与运行期状态。作者在 Agent 配置的 Aim 里填写两半:偏航(FAimYaw:蒙版骨、对称限位、速度、加速度、静止角)与俯仰(FAimPitch:蒙版骨、上下限、速度、加速度、静止角),以及瞄准窗口与两个到位容差。运行期角度由模拟积分写入 FAiming,瞄准行为读它判断「关节是否已对准目标」。
Everything the aim joint is configured with, plus its runtime state. On the agent's Aim config the author fills two halves: yaw (FAimYaw: mask bone, symmetric limit, speed, acceleration, rest angle) and pitch (FAimPitch: mask bone, lower/upper bounds, speed, acceleration, rest angle), plus the aim window and the two on-target tolerances. The runtime angles are integrated into FAiming, which the Aim behaviour reads to decide whether the joint already points at the target.
FAimYaw USTRUCT
瞄准关节的偏航一半:蒙版根连同其整棵子树随瞄准偏航一起摆动。默认值按人形弓手设定(躯干扭转 120 度/秒、720 度/秒²),与俯仰一半各用一套速率——腰转得比肩抬得快。
The yaw half of the aim joint: the mask root and its whole subtree swing with the aim yaw. The defaults model a humanoid archer (torso twist at 120 deg/s and 720 deg/s²); each half keeps its own rates because a waist turns faster than a shoulder lifts.
成员变量Members
| 名称Name | 类型Type | 默认值 | 说明Description |
|---|---|---|---|
Bone | FName | None | 偏航的蒙版根:这根骨连同整棵子树随瞄准偏航一起摆。留空 = 不做偏航。烘焙时按源骨架解析。Mask root of the yaw: this bone and its whole subtree swing with the aim yaw. Empty = no yaw. The bake resolves it against the source skeleton. |
Limit | float | 90 度deg | 偏航相对身体最多偏离多少度,按对称范围钳制;180 = 无限。How far the yaw may deviate from the body, applied as a symmetric clamp;180 = unlimited. |
Speed | float | 120 度/秒deg/s | 模拟求解器可以命令的最大偏航速度;0 = 直接取目标。Maximum yaw speed the sim may command;0 = snap straight to the target. |
Acceleration | float | 720 度/秒²deg/s² | 偏航角加速度;0 = 角速度立即取到期望速度,不做斜坡。Yaw acceleration;0 = the angular velocity takes the desired speed immediately, with no ramp. |
Rest | float | 0 度deg | 没有可用目标时保持的偏航角。运行期直接使用该值,不会再按 Limit 钳制,所以这里的钳制(±180)保证静止角不超出一整圈。Yaw held while no target is available. The runtime uses it without re-clamping it to Limit, so the ±180 authoring clamp keeps the rest angle inside a full turn. |
方法Methods
按值比较全部五个作者字段。调参不同的两个单位因此不会共用同一份偏航配置。
Compares all five authored fields by value, so two units tuned differently never share one yaw configuration.
Input
| 参数Param | 类型Type | 说明Description |
|---|---|---|
Other | const FAimYaw& | 要比较的另一份配置。The other configuration to compare against. |
Output
五个字段全部相等返回 true。
Returns true when all five fields are equal.
FAimPitch USTRUCT
瞄准关节的俯仰一半:炮管在偏航子树内做俯仰。默认值按持弓臂抬起 60 度/秒、360 度/秒² 设定。
The pitch half of the aim joint: the barrel tilts inside the yaw subtree. Defaults model a bow arm lifting at 60 deg/s with 360 deg/s² of acceleration.
成员变量Members
| 名称Name | 类型Type | 默认值 | 说明Description |
|---|---|---|---|
Bone | FName | None | 俯仰组的蒙版根:这根骨连同其子树随瞄准俯仰倾斜。通常位于偏航子树内,独立段落也允许。留空 = 不做俯仰。Mask root of the pitch group: this bone and its subtree tilt with the aim pitch. It usually sits inside the yaw subtree; an independent segment is allowed. Empty = no pitch. |
Min | float | -30 度deg | 俯仰下限,相对身体计;不得大于 Max。Lower pitch bound relative to the body; must not exceed Max. |
Max | float | 60 度deg | 俯仰上限,相对身体计;不得小于 Min。Upper pitch bound relative to the body; must not be below Min. |
Speed | float | 60 度/秒deg/s | 模拟求解器可以命令的最大俯仰速度;0 = 直接取目标。Maximum pitch speed the sim may command;0 = snap straight to the target. |
Acceleration | float | 360 度/秒²deg/s² | 俯仰角加速度;0 = 角速度立即取到期望速度,不做斜坡。Pitch acceleration;0 = the angular velocity takes the desired speed immediately, with no ramp. |
Rest | float | 0 度deg | 没有可用目标时保持的俯仰角。运行期直接使用该值,不会再按 Min / Max 钳制。Pitch held while no target is available. The runtime uses it without re-clamping it to Min / Max. |
方法Methods
按值比较全部六个作者字段。调参不同的两个单位因此不会共用同一份俯仰配置。
Compares all six authored fields by value, so two units tuned differently never share one pitch configuration.
Input
| 参数Param | 类型Type | 说明Description |
|---|---|---|
Other | const FAimPitch& | 要比较的另一份配置。The other configuration to compare against. |
Output
六个字段全部相等返回 true。
Returns true when all six fields are equal.
FAim USTRUCT
一个单位唯一的作者瞄准配置(FA_MassBattleBaseFragment 派生),分偏航与俯仰两半,另带瞄准窗口与两个到位容差。每个 Agent 模板都携带本片段,从数据资产拷贝而来。作者调参只在这里,运行期状态在 FAiming。
The single authored aim configuration of one unit (derived from FA_MassBattleBaseFragment), split into a yaw and a pitch half plus the aim window and two on-target tolerances. Every agent template carries it, copied over from the data asset. Authoring lives only here; runtime state lives in FAiming.
成员变量Members
| 名称Name | 类型Type | 默认值 | 说明Description |
|---|---|---|---|
AimTimeRange | FVector2f | (0, 3) 秒s | 瞄准窗口(X=最短,Y=最长),由瞄准行为读取:关节到位且已过最短时间即算对准;最长时间用尽仍未到位则窗口超时。结果送往行为切换表的 OnAimAligned 或 OnAimTimeout。Aim window (X=Min, Y=Max) read by the Aim behaviour: alignment counts as achieved once Min has elapsed with the joint on target; the window times out when Max elapses without one. The result routes to OnAimAligned or OnAimTimeout in the behaviour transition table. |
AngleToleranceATK | float | 15 度deg | 偏航容差:只有偏航与目标的夹角在此以内,关节才算对准。Yaw tolerance: the joint counts as aligned only while its yaw is within this many degrees of the target. |
PitchToleranceATK | float | 10 度deg | 俯仰容差:只有俯仰与目标的夹角在此以内,关节才算对准。骨架没有烘出俯仰关节时这一项不参与判定。Pitch tolerance: the joint counts as aligned only while its pitch is within this many degrees of the target. It does not participate when the rig bakes no pitch joint. |
Yaw | FAimYaw | — | 瞄准关节的偏航一半:蒙版骨、对称限位、速度、加速度、静止角。The yaw half of the aim joint: mask bone, symmetric limit, speed, acceleration, rest angle. |
Pitch | FAimPitch | — | 瞄准关节的俯仰一半:蒙版骨、上下限、速度、加速度、静止角。The pitch half of the aim joint: mask bone, lower/upper bounds, speed, acceleration, rest angle. |
FAiming USTRUCT
一个单位瞄准关节的运行期状态(FA_MassBattleBaseFragment 派生):相对车体的偏航/俯仰角,以及两轴当前各自的角速度。由模拟积分、进快照与模拟哈希;每个 Agent 模板都无条件携带它,瞄准行为因此无需额外配置即可读取。
The runtime state of one unit's aim joint (derived from FA_MassBattleBaseFragment): the yaw/pitch angle relative to the chassis and the angular velocity each axis is moving at. Integrated by the sim and carried in the snapshot and simulation hash; every agent template carries it unconditionally, so the Aim behaviour needs no extra setup to read it.
成员变量Members
| 名称Name | 类型Type | 默认值 | 说明Description |
|---|---|---|---|
Yaw | float | 0 度deg | 瞄准偏航相对车体的当前角度,在模拟中积分,进快照与哈希。Current aim yaw relative to the chassis, integrated in sim, snapshotted and hashed. |
Pitch | float | 0 度deg | 瞄准俯仰相对车体俯仰的当前角度,在模拟中积分,进快照与哈希。Current aim pitch relative to the chassis, integrated in sim, snapshotted and hashed. |
YawVelocity | float | 0 度/秒deg/s | 瞄准关节的偏航角速度,在模拟中积分,进快照与哈希。Current yaw angular velocity of the aim joint, integrated in sim, snapshotted and hashed. |
PitchVelocity | float | 0 度/秒deg/s | 瞄准关节的俯仰角速度,在模拟中积分,进快照与哈希。Current pitch angular velocity of the aim joint, integrated in sim, snapshotted and hashed. |
方法Methods
把四个运行期值全部归零(角度与两轴角速度)。用于实体复用或重新开始时清空瞄准状态。
Zeroes all four runtime values (both angles and both angular velocities), for entity reuse or a clean restart of the aim state.
Input
无参数。
No parameters.
Output
无返回值。副作用:Yaw / Pitch / YawVelocity / PitchVelocity 全部写 0。
No return value. Side effect:Yaw / Pitch / YawVelocity / PitchVelocity are all written to 0.
边界与注意Caveats
瞄准不是攻击回合的一个相位。开火前先进入瞄准行为:武器就绪且与目标的表面距离在攻击距离内时请求瞄准;关节到位并且已过瞄准窗口的最短时间,才把回合交给行为切换表 OnAimAligned 指定的行为(默认攻击)。瞄准行为本身不推进攻击时钟。
Aim is not a phase of the attack round. Aiming runs before the shot: it is requested when the weapon is ready and the surface-to-surface distance is within attack range. Once the joint is on target and the aim window's minimum time has elapsed, the round is handed to the behaviour named by OnAimAligned (Attack by default). The Aim behaviour never advances the attack clock.
超时会惩罚。瞄准窗口的最长时间用尽仍未对准时,本轮记为瞄准超时:bAimFailed 置位,武器从零开始走一次完整冷却后才能再次尝试。到达最长时间但角度已有效时,走的是上面的对准分支,不会失败。
A timeout costs a cooldown. If the window's maximum elapses without alignment the attempt is a timeout:bAimFailed is set and the weapon must run a full cooldown from zero before trying again. Reaching the maximum with a valid angle takes the aligned branch instead, so it does not fail.
没有关节也能开火。骨架没有解析出偏航关节时,身体前向就是瞄准方向,只有偏航参与判定(2D 锥),此时偏航容差就是开火锥的半角。骨架解析出偏航关节但没有俯仰关节时,俯仰容差不参与判定。
A shot still works without a joint. When the skeleton resolves no yaw joint, the body's forward direction is the aim and only yaw participates (a 2D cone), so the yaw tolerance is the cone's half-angle. When a yaw joint exists but no pitch joint is baked, the pitch tolerance does not participate.
骨名要靠烘焙落地。偏航与俯仰的骨名由烘焙解析成骨骼下标;没有解析出来(骨名留空、骨架里没有这根骨,或还没有烘焙)时,瞄准关节保持关闭,单位按上一条的无关节方式开火。下标存在于 Bone Shared 片段上,不在这里。
Bone names only take effect after a bake. The bake resolves the yaw and pitch bone names into skeleton indices. If they are not resolved (empty names, bones absent from the skeleton, or no bake yet), the aim joint stays off and the unit fires the joint-less way described above. The indices live on the Bone Shared fragment, not here.
静止角不受限位钳制。Rest 在没有目标时直接生效:偏航静止角不会再按 Limit 收拢,俯仰静止角也不会再按 Min / Max 收拢。作者侧的钳制范围只保证它不超出一整圈 / 不超出作者填写范围。
The rest angle is not re-clamped. Rest applies directly while no target is available: the yaw rest is not pulled back into Limit, and the pitch rest is not pulled into Min / Max. The authoring clamps only keep it inside a full turn / inside the authored range.
配置与状态分开同步。FAim 是配置,不进快照、也不进模拟哈希;改了它属于配置改动。FAiming 是模拟状态,进快照与哈希——它决定对准是否达成、窗口是否超时,所以两端的分叉会以失步的形式暴露出来。不要在运行期手写 FAiming 的字段来「修正」瞄准,那等于直接改写模拟状态。
Config and state sync differently. FAim is configuration and enters neither the snapshot nor the simulation hash; changing it is a config change. FAiming is simulation state and is snapshotted and hashed — it decides whether alignment is achieved and whether the window times out, so a divergence shows up as a desync. Do not hand-write its fields at runtime to "correct" the aim; that rewrites simulation state directly.