本文与游戏《传送门2》有关。点击这里查看更多信息。
This article relates to the game "Team Fortress 2". Click here for more information.
This article relates to the game "Garry's Mod". Click here for more information.

trigger_catapult

From Valve Developer Community
< Zh
Revision as of 01:01, 30 June 2025 by WoShiGeNiCheng (talk | contribs) (→‎键值)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
English (en)中文 (zh)Translate (Translate)

trigger_catapult是一个笔刷实体,可在传送门2 传送门2军团要塞2 军团要塞2Garry's Mod Garry's Mod中使用。 在Alien Swarm: Reactive Drop Alien Swarm: Reactive Drop中也有名为trigger_catapult的实体,但它似乎是功能不同的另一个实体。

该实体用于将玩家或其他物体弹射到空中。 它能够设置实体的飞行方向或目标,考虑其当前速度,并且(对玩家而言)能抑制其控制,这使其成为控制飞行轨迹和落点的强大工具。

传送门2 通常用于空中信仰板(en)来实现一种不一定需要玩家使用传送门的抛射(en)效果。

配置

弹射方向由键值Launch target(弹射目标)Launch direction(弹射方向)决定。如果设置了前者,后者将被忽略。除此之外,地图制作者可以设定实体被弹射所需满足的最小/最大速度和方向条件。

Warning.png警告:如果实体以0速度被弹射,游戏会崩溃。

弹射目标

// 模拟带弹射目标的trigger_catapult的Squirrel函数
// trigger_catapult(被弹射实体句柄, 目标向量, 速度)
::trigger_catapult <- function(ent, target, speed=450)
{
	local g = 600                          // sv_gravity
	local d = target - ent.GetOrigin()     // 从起点到目标的向量
	local t = d.Length() / speed           // 飞行所需时间(秒)
	local vz = d.z / t + 0.5 * g * t       // 所需的初始z轴速度
	local v = Vector(d.x / t, d.y / t, vz) // v.Length()是阈值基准
	ent.SetVelocity(v)
}

最简单的配置是创建或找到一个实体(如info_target(en)或其他任何实体),将其原点放置在玩家或物体应该飞向的位置,并在trigger_catapultLaunch target(弹射目标)键值中指定该实体的名称。

设置完成后,两个速度键值将决定飞行高度,通常更高的速度会使弹射轨迹更平缓,而更低的速度会使轨迹更陡峭。实际弹射速度也会根据触碰trigger_catapult的位置略有不同(因为不能平等对待每个弹射位置)。如果被弹射物体在弹射后受到重力以外的力影响,将会错过目标。

如果设置了Launch target|弹射目标且符合条件的物体触碰到trigger_catapult,游戏会通过两者初始距离除以相应速度键值来计算物体到达目标所需时间(这就是为什么当速度恰好为0时游戏会崩溃):时间 = 距离 / 速度。基于这个时间,游戏会按照右侧代码所示将物体射向精确计算的方向,使其正好在计算时间内到达目标。游戏想要射击实体的速度是最终阈值检查的基准值,详见下文。总之,这就是为什么设置非常低的速度会导致极高的向上弹射速度——因为低速度意味着物体需要更长时间才能到达目标。

Why?: 如果Use Exact Velocity(使用精确速度)设为Yes(是)且指定了Launch target(弹射目标),即使增加速度也无济于事,游戏仍可能在控制台(使用developer 1时)打印"Catapult can't hit target! Add more speed!"(弹射器无法命中目标!请增加速度!)。

弹射方向

也可以留空Launch target(弹射目标)而设置Launch direction(弹射方向)。在这种情况下,速度键值真正代表物体将被弹射的速度,除非Launch direction(弹射方向)键值设为Up(向上)(精确为-90 0 0),此时弹射速度会是设定值的1.5倍(这与Use Exact Velocity(使用精确速度)键值无关)。要在Up-90 0 0)情况下达到起始高度h的最大高度,请将速度设为sqrt(h) * 23.1

一般来说,如果实体以speed单位/秒的速度和pitch角度(0到-90,0表示水平,-90表示垂直向上)被弹射,则被弹射物体将在t = speed * sin(-pitch) / sv_gravity(en)秒后到达最高点,该点比弹射点高t2 * sv_gravity / 2单位,并在x-y平面上偏移t * speed * cos(pitch)单位。

速度阈值

如果Use Threshold Check(使用阈值检查)设为Yes,此trigger_catapult只会在实体速度至少为speed * (1 - lowerThreshold)单位/秒且至多为speed * (1 + upperThreshold)单位/秒时弹射该实体,其中speed是游戏想要射击实体的速度。如果没有设置Launch target(弹射目标),它等于相应的速度键值,否则是游戏计算的值,见上方代码。
传送门 2:社区特供版 如果Use Absolute Threshold Check(使用绝对阈值检查)设为Yes(是),阈值键值代表实际速度而非百分比。

此外,Entry Angle Tolerance(进入角度容差)可用于限制实体速度必须指向的方向才能被弹射。如果设为x,则只有当实体进入速度与从弹射位置到目标的向量之间的夹角不超过cos-1(x)时才会被弹射,其中x = 0表示最多偏离90°,x = -1表示总是弹射(最多偏离180°),参见点积(en)

抑制玩家控制

Air Control Supression Time(空中控制抑制时间)可用于防止玩家通过侧移偏离预期的弹射轨迹。它会在弹射后固定时间内禁用玩家的空中控制。即使玩家已经着陆,此效果也不会结束,因此地图制作者可能需要通过游戏内测量(如使用host_timescale(en)printl(Time())(en))来精确设置这个持续时间。
为了获得可预测的弹射轨迹,这有助于消除一个干扰因素,但还需要考虑其他因素,例如传送门漏斗效应(en)、静态障碍物、其他不可预测的飞行物体、trigger_push(en)、枪火、sv_maxvelocity(en)(默认为3500单位/秒)等。

测试

如果编译地图后对配置不满意,无需重新编译即可测试不同配置:在游戏中使用ent_fire(en) <trigger_catapult名称> addoutput(en) "<键值> <值>"更改trigger_catapult的键值。如果没有名称,使用trigger_catapult作为名称以定位所有此类实体。通过ent_fire所做的所有更改在地图更换或重新加载时都会被丢弃。

在游戏中,可以使用命令Template:Developertrigger_catapult(en)trigger_catapult(en)查看预测的弹射轨迹。将developer设为≥1还会在控制台打印关于正在进行的阈值检查的调试信息。

键值

Player Speed (playerSpeed) <浮点型(en)>
玩家速度
Physics Object Speed (physicsSpeed) <浮点型(en)>
物理对象速度。分别用于弹射玩家/物理对象的速度(单位/秒)。如果设置了弹射目标,此速度仅指起点到目标点的距离。设为0将在下次使用时导致游戏崩溃!
Use Threshold Check (useThresholdCheck) <布尔值(en)>
使用阈值检查。如果设为是,则只有当玩家/物体的速度在下限和上限阈值规定的范围内时才会被弹射。
Entry Angle Tolerance (entryAngleTolerance) <浮点型(en)>
进入角度容差。被弹射物体的速度必须指向目标的程度。指定[-1...1]之间的值,1表示精确对准,0表示180度内,-1表示接受任何角度。仅在启用使用阈值检查时使用。
Use Exact Velocity (useExactVelocity) <布尔值(en)>
使用精确速度。尝试以精确指定的速度弹射 - 这会防止弹射目标带来的额外向上速度。
Exact Solution Method (exactVelocityChoiceType) <choices>
精确解方法。使用精确速度会生成两个正确解,精确计算物体速度和角度。用此强制选择其中一个。
  • 0 : 最佳
  • 1 : 解一
  • 2 : 解二
Lower Threshold (lowerThreshold) <浮点型(en)>
下限阈值。被弹射物体必须在此百分比值内才能激活弹射。指定值从玩家速度键值中减去。指定[0...1]之间的值(默认为.15)。仅在启用使用阈值检查时使用。
Upper Threshold (upperThreshold) <浮点型(en)>
上限阈值。被弹射物体必须在此百分比值内才能激活弹射。指定值加到玩家速度键值上。指定[0...1]之间的值(默认为.30)。仅在启用使用阈值检查时使用。
Launch direction (launchDirection) <angle(en)>
弹射方向。弹射玩家的方向。如果设置了弹射目标,此键值将被忽略。
Launch target (launchTarget) <target_destination>
弹射目标。弹射时尝试"命中"的实体。
Only check velocity (onlyVelocityCheck) <布尔值(en)>
仅检查速度。仅检查触碰对象的速度 - 不实际弹射它。与OnCatapulted配合使用可创建速度检查触发器。仅在启用使用阈值检查时有效。
Apply angular impulse (applyAngularImpulse) <布尔值(en)>
应用角冲量。是否对被弹射的物理对象施加随机角冲量。
Air Control Supression Time (AirCtrlSupressionTime) <浮点型(en)>
空中控制抑制时间。[仅限目标弹射!]如果大于零,按此数值(秒)抑制玩家空中控制。如果小于零使用默认值(0.25秒)。
Icon-Bug.png错误:军团要塞2中无效。  [todo tested in ?]
Note.png注意:
  • 即使玩家已经着陆,抑制仍然有效。
  • 这有助于获得可预测的弹射轨迹,但可能还需要考虑其他因素,见上文。
Use Absolute Threshold Check ([todo internal name (i)]) <布尔值(en)> (存在于 传送门 2:社区特供版 之中)
使用绝对阈值检查。如果为真,阈值代表实际速度而非百分比
BaseTrigger
Filter Name (filtername) <filter(en)>
A filter entity to test potential activators against.
Start Disabled (StartDisabled) <布尔值(en)>
Stay dormant until activated (with theEnableinput).

标志

BaseTrigger
Everything (not including physics debris) : [64]
Clients (Survivors, Special Infected, Tanks 求生之路系列求生之路系列 之中) : [1]
Only clients in vehicles : [32]
Only clients *not* in vehicles : [512]
Disallow Bots (被移除求生之路 以来) : [4096]
NPCs (Common Infected, Witches 求生之路系列求生之路系列 之中) : [2]
Only player ally NPCs : [16]
Only NPCs in vehicles (respects player ally flag) : [2048]
Physics Objects (not including physics debris) : [8]
Physics debris (include also physics debris) : [1024]
Pushables (Passes entities with classname func_pushable) : [4] Obsolete
已弃用。
Equivalent to using Everything + filter_activator_class that filters func_pushable.

输入

BaseTrigger
Toggle
Toggles this trigger between enabled and disabled states.
Enable
Enable trigger
Disable
Disable trigger
TouchTest  (存在于自 起源2007 以来)
Triggers either the OnTouching or OnNotTouching outputs for whether anything is touching this entity.
Icon-Bug.png错误:Sleeping prop_physics will never fire "OnTouching". Also applies to entities using prop_physics as base.  (tested in: 半衰期2)
StartTouch  (存在于自 起源2007 以来) 不存在于FGD!
Behave as if the !caller entity had just entered the trigger volume. Accepts non-physical entities.
EndTouch  (存在于自 起源2007 以来) 不存在于FGD!
Behave as if !caller had just exited the trigger volume.
DisableAndEndTouch  (存在于 起源2013 多人分支军团要塞2分支 之中)
Disables this trigger and calls EndTouch on all currently-touching entities.

输出

OnCatapulted
当物体已被弹射或本应被弹射时触发(如果onlyVelocityCheck设为Yes
BaseTrigger
OnStartTouch
!activator = entity that caused this output
!caller = this entity
Fired when a valid entity starts touching this trigger.
OnStartTouchAll
!activator = entity that caused this output
!caller = this entity
Fired when a valid entity starts touching this trigger, and no other entities are touching it. If there are any other entities touching the trigger when a new one begins to touch, only OnStartTouch will fire.
OnEndTouch
!activator = entity that caused this output
!caller = this entity
Fired when a valid entity stops touching this trigger.
Note.png注意:Will also fire for entities touching it when trigger is disabled via Disable input
Warning.png警告:This includes entities which are deleted while inside the trigger. In this case !activator will be invalid.
Warning.png警告:OnEndTouch can fire before OnStartTouch under certain circumstances[如何?] where both are fired on the same tick and each have the same delay.
Note.png修复:Add a slight delay to OnEndTouch.
OnEndTouchAll
!activator = entity that caused this output
!caller = this entity
Fired when all valid entities stop touching this trigger.
OnTouching  (存在于自 起源2007 以来)
!activator = !caller = this entity
Fired if something is currently touching this trigger when TouchTest is fired.
OnNotTouching  (存在于自 起源2007 以来)
!activator = !caller = this entity
Fired if nothing is currently touching this trigger when TouchTest is fired.