This repository has been archived by the owner on Mar 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.nut
80 lines (65 loc) · 2.75 KB
/
example.nut
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
IncludeScript("portal2-BBoxCast/bboxcast.nut")
customSettings <- {
// ignoreClass = ["trigger_", ...],
// The ignoreClass setting accepts a mask for ignoring entities. Since we want to ignore all triggers with "trigger_",
// we need to utilize the priorityClass setting to ensure that the ray still hits "trigger_portal_cleanser".
priorityClass = ["trigger_portal_cleanser"]
}
// Function to print trace information
function PrintTraceInfo(trace)
{
printl("Start Position: " + trace.GetStartPos())
printl("End Position: " + trace.GetEndPos())
printl("Hit Position: " + trace.GetHitpos())
printl("Hit Entity: " + trace.GetEntity())
printl("Did Hit: " + trace.DidHit())
printl("Did Hit World: " + trace.DidHitWorld())
printl("Fraction Traversed: " + trace.GetFraction())
}
// Function to perform a single ray trace
function TestRay()
{
local startpos = EntityGroup[0].GetOrigin()
local endpos = EntityGroup[1].GetOrigin()
// Perform bboxcast trace from startpos to endpos, without custom settings
local bboxTrace = bboxcast(startpos, endpos)
// Print trace information
PrintTraceInfo(bboxTrace)
// Visualize the trace by drawing a line from startpos to hitpos
DebugDrawLine(startpos, bboxTrace.GetHitpos(), 255, 255, 255, false, 1)
// If the trace hit an entity, move another entity to the hit position and enable its output
if (bboxTrace.DidHit()) {
EntityGroup[2].SetOrigin(bboxTrace.GetHitpos())
EntFire("hitpos", "enable")
}
else {
EntFire("hitpos", "disable")
}
}
// Function to continuously perform ray traces until a specified time
function TestRayLoop(time = null)
{
local startpos = EntityGroup[0].GetOrigin()
local endpos = EntityGroup[1].GetOrigin()
// If no time is specified, calculate a time value based on current time
if (!time) time = abs(Time()) + 11
// Exit the loop when the specified time is reached
if (abs(Time()) == time)
return
// Perform bboxcast trace from startpos to endpos, with custom settings
local bboxTrace = bboxcast(startpos, endpos, null, customSettings)
// Print trace information
PrintTraceInfo(bboxTrace)
// Visualize the trace by drawing a line from startpos to hitpos
DebugDrawLine(startpos, bboxTrace.GetHitpos(), 255, 0, 255, false, FrameTime() * 2)
// If the trace hit an entity, move another entity to the hit position and enable its output
if (bboxTrace.DidHit()) {
EntityGroup[2].SetOrigin(bboxTrace.GetHitpos())
EntFire("hitpos", "enable")
}
else {
EntFire("hitpos", "disable")
}
// Schedule the next iteration of the loop
EntFireByHandle(self, "runscriptcode", "TestRayLoop(" + time + ")", FrameTime(), null, null)
}