本文与游戏《传送门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 00:16, 30 June 2025 by WoShiGeNiCheng (talk | contribs) (Created page with "{{LanguageBar|trigger_catapult}} <!-- 当本页面更新为使用{{langsp}}或{{language subpage}}而非{{lang}}时,请将{{this is a}}移至基础页面,因为它会自动翻译。--> {{GMOD topicon}} {{P2 topicon}} {{TF2 topicon}} {{this is a|笔刷实体|name=trigger_catapult|game=传送门2|game1=军团要塞2|game2=盖瑞模组}} 在{{asrd|4}}中也有名为<code>trigger_catapult</code>的实体,但它似乎是功能不同的另一个实体。 <!-- 注释节...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
English (en)中文 (zh)Translate (Translate)

trigger_catapult是一个笔刷实体,可在Template:传送门2Template:军团要塞2Template:盖瑞模组中使用。

Warning.png警告:
  • The {{{game}}} parameter is inconsistent with the name defined by the {{传送门2}} template.
  • The {{{game1}}} parameter is inconsistent with the name defined by the {{军团要塞2}} template.
  • The {{{game2}}} parameter is inconsistent with the name defined by the {{盖瑞模组}} template.
    If a parameter is consistent but you're still seeing this warning, it may be an issue with the template itself. Please discuss it on the template's talk page.

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

弹射方向

也可以留空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所做的所有更改在地图更换或重新加载时都会被丢弃。

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

键值

Player Speed (playerSpeed) <玩家速度(en)>
float
Physics Object Speed (physicsSpeed) <物理对象速度(en)>
float
Use Threshold Check (useThresholdCheck) <使用阈值检查(en)>
boolean
Entry Angle Tolerance (entryAngleTolerance) <进入角度容差(en)>
float
Use Exact Velocity (useExactVelocity) <使用精确速度(en)>
boolean
Exact Solution Method (exactVelocityChoiceType) <精确解方法(en)>
choices
  • 0 : 最佳
  • 1 : 解一
  • 2 : 解二
Lower Threshold (lowerThreshold) <下限阈值(en)>
float
Upper Threshold (upperThreshold) <上限阈值(en)>
float
Launch direction (launchDirection) <弹射方向(en)>
angle
Launch target (launchTarget) <弹射目标(en)>
target_destination
Only check velocity (onlyVelocityCheck) <仅检查速度(en)>
boolean
Apply angular impulse (applyAngularImpulse) <应用角冲量(en)>
boolean
Air Control Supression Time (AirCtrlSupressionTime) <空中控制抑制时间(en)>
float
Use Absolute Threshold Check ([todo internal name (i)]) <使用绝对阈值检查(en)> (存在于 传送门 2:社区特供版 之中)
boolean
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.