Dota 2 Workshop Tools/Scripting/API/Global.TraceHull=zh: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
(Created page with "{{Note | This page was previously automatically generated. Any changes may be overwritten}} Category:Dota2Function Category:Global == Function Description == ''' b...")
 
No edit summary
Line 8: Line 8:
''' bool TraceHull(table ''parameters'') '''
''' bool TraceHull(table ''parameters'') '''


Traces a bounding box along a line. The bounding box center follows the line.
沿线段追踪边界体。边界体中心沿线。




Line 14: Line 14:
;Example
;Example
<source lang="lua">
<source lang="lua">
-- Traces a line 100 units forward from the postion of the player, using the players bounding box.
-- 使用玩家边界体,从玩家的位置向前追踪100个单位。
-- If the trace hits, a line is drawn to the hit position.
-- 如果命中,则会在命中位置绘制一条线。
local playerEnt = Entities:FindByClassname(nil, "player")
local playerEnt = Entities:FindByClassname(nil, "player")
local startVector = playerEnt:GetCenter()
local startVector = playerEnt:GetCenter()
Line 23: Line 23:
endpos = startVector + RotatePosition(Vector(0,0,0), playerEnt:GetAngles(), Vector(100, 0, 0));
endpos = startVector + RotatePosition(Vector(0,0,0), playerEnt:GetAngles(), Vector(100, 0, 0));
ignore = playerEnt;
ignore = playerEnt;
mask =  33636363; -- TRACE_MASK_PLAYER_SOLID from L4D2 script API, may not be correct for Source 2.
mask =  33636363; -- L4D2脚本API中的TRACE_MASK_PLAYER_SOLID对于源2可能不正确。
min = playerEnt:GetBoundingMins();
min = playerEnt:GetBoundingMins();
max = playerEnt:GetBoundingMaxs()
max = playerEnt:GetBoundingMaxs()
Line 39: Line 39:
</source>
</source>


== Parameters ==
== 参数 ==
{| class="standard-table" style="width: 50%;"
{| class="standard-table" style="width: 50%;"
! Type
! 类型
! Name
! 名字
! Description
! 介绍
|-
|-
| table
| table
| parameters
| parameters
| Table used for both input and output.
| 用于输入和输出的表。
|}
|}


== Returns ==
== 返回 ==


''bool'' - Whether the trace is successful. This only indicates that the trace was done, not whether it hit anything.
''bool'' - 追踪是否成功。这仅指示追踪已完成,而不是是否击中任何东西。


== Input Parameters ==
== Input Parameters ==
Passed to the ''parameters'' table to set up the trace.
传递到参数表以设置跟踪。


{| class="standard-table" style="width: 50%;"
{| class="standard-table" style="width: 50%;"
! Type
! 类型
! Name
! 名字
! Description
! 介绍
|-
|-
| Vector
| Vector
| startpos
| startpos
| Global vector where to start the trace.
| 指示追踪开始位置的全局向量。
|-
|-
| Vector
| Vector
| endpos
| endpos
| Global vector where to end the trace.
| 指示追踪结束位置的全局向量。
|-
|-
| Vector
| Vector
| min
| min
| Minimum extents of the bounding box.
| 边界体的最小范围。
|-
|-
| Vector
| Vector
| max
| max
| Maximum extents of the bounding box.
| 边界体的最大范围。
|-
|-
| int
| int
| mask
| mask
| Collision type bitmask.
| 碰撞类型位掩码。
|-
|-
| CBaseEntity
| CBaseEntity
| ignore
| ignore
| Entity to ignore when tracing.
| 追踪时欲忽略的实体。
|}
|}


== Output parameters ==
== 输出参数 ==
Output written by the function to the ''parameters'' table.
本函数写到table中的成员。
{{Note | These parameters may not exist if the trace does not hit. Check for nil before using.}}
{{Note | 如果未命中跟踪,则这些参数可能不存在。使用前检查是否为空。}}


{| class="standard-table" style="width: 50%;"
{| class="standard-table" style="width: 50%;"
! Type
! 类型
! Name
! 名字
! Description
! 介绍
|-
|-
| Vector
| Vector
| pos
| pos
| Global vector along the line where the bounding box hit.
| 存储沿边界体命中位置的全局向量。
|-
|-
| float
| float
| fraction
| fraction
| Fraction from the start to end where the trace hit.
| 在追踪轴上移动距离的百分比(?)
|-
|-
| bool
| bool
| hit
| hit
| Whether the trace hit something. Always present.
| 是否命中。始终会存在。
|-
|-
| CBaseEntity
| CBaseEntity
| enthit
| enthit
| Handle of the entity the trace hit.
| 追踪命中的实体的句柄。
|-
|-
| bool
| bool
| startsolid
| startsolid
| Whether the trace started inside something. {{Note | This parameter is set to nil if it is false}}
| 追踪是否在实体内部开始。 {{Note | 如果为false,则此参数设置为 nil}}
|-
|-
| Vector
| Vector
| normal
| normal
| World space normal vector of the surface hit.
| 命中的曲面的全局法线向量。
|}
|}

Revision as of 04:51, 8 October 2023

Note.pngNote: This page was previously automatically generated. Any changes may be overwritten

Function Description

bool TraceHull(table parameters)

沿线段追踪边界体。边界体中心沿线。


Example
-- 使用玩家边界体,从玩家的位置向前追踪100个单位。
-- 如果命中,则会在命中位置绘制一条线。
local playerEnt = Entities:FindByClassname(nil, "player")
local startVector = playerEnt:GetCenter()
local traceTable =
{
	startpos = startVector;
	endpos = startVector + RotatePosition(Vector(0,0,0), playerEnt:GetAngles(), Vector(100, 0, 0));
	ignore = playerEnt;
	mask =  33636363; -- L4D2脚本API中的TRACE_MASK_PLAYER_SOLID对于源2可能不正确。
	min = playerEnt:GetBoundingMins();
	max = playerEnt:GetBoundingMaxs()
}

TraceHull(traceTable)

if traceTable.hit 
then
	DebugDrawLine(traceTable.startpos, traceTable.pos, 0, 255, 0, false, 1)
	DebugDrawLine(traceTable.pos, traceTable.pos + traceTable.normal * 10, 0, 0, 255, false, 1)
else
	DebugDrawLine(traceTable.startpos, traceTable.endpos, 255, 0, 0, false, 1)
end

参数

类型 名字 介绍
table parameters 用于输入和输出的表。

返回

bool - 追踪是否成功。这仅指示追踪已完成,而不是是否击中任何东西。

Input Parameters

传递到参数表以设置跟踪。

类型 名字 介绍
Vector startpos 指示追踪开始位置的全局向量。
Vector endpos 指示追踪结束位置的全局向量。
Vector min 边界体的最小范围。
Vector max 边界体的最大范围。
int mask 碰撞类型位掩码。
CBaseEntity ignore 追踪时欲忽略的实体。

输出参数

本函数写到table中的成员。

Note.pngNote: 如果未命中跟踪,则这些参数可能不存在。使用前检查是否为空。
类型 名字 介绍
Vector pos 存储沿边界体命中位置的全局向量。
float fraction 在追踪轴上移动距离的百分比(?)
bool hit 是否命中。始终会存在。
CBaseEntity enthit 追踪命中的实体的句柄。
bool startsolid 追踪是否在实体内部开始。
Note.pngNote: 如果为false,则此参数设置为 nil
Vector normal 命中的曲面的全局法线向量。