Skip to content

Commit 2bbb386

Browse files
rumourArtldg
authored andcommitted
make !beamer more reliable and stuck in walls less (if at all!)
1 parent ab75ef4 commit 2bbb386

File tree

1 file changed

+26
-14
lines changed

1 file changed

+26
-14
lines changed

addons/sourcemod/scripting/shavit-zones.sp

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2303,6 +2303,14 @@ public Action Command_ReloadZoneSettings(int client, int args)
23032303
return Plugin_Handled;
23042304
}
23052305

2306+
// Was originally used in beamer to replicate this gmod lua code:
2307+
/*
2308+
My code from tracegun.lua that I based this off of:
2309+
local ang = tr.Normal:Angle() // calculate in SP with: ( traceRes.HitPos - traceRes.StartPos ):Normalize()
2310+
ang:RotateAroundAxis(tr.HitNormal, 180)
2311+
local dir = ang:Forward()*-1
2312+
tr = util.TraceLine({start=tr.HitPos, endpos=tr.HitPos+(dir*100000), filter=players})
2313+
*/
23062314
stock void RotateAroundAxis(float v[3], const float in_k[3], float theta)
23072315
{
23082316
// https://en.wikipedia.org/wiki/Rodrigues%27_rotation_formula#Statement
@@ -2329,6 +2337,23 @@ stock void RotateAroundAxis(float v[3], const float in_k[3], float theta)
23292337
}
23302338
}
23312339

2340+
stock void ReflectAngles(float direction[3], const float normal[3])
2341+
{
2342+
float fwd[3], reflected[3];
2343+
2344+
GetAngleVectors(direction, fwd, NULL_VECTOR, NULL_VECTOR);
2345+
2346+
float dot = GetVectorDotProduct(fwd, normal);
2347+
2348+
for (int i = 0; i < 3; i++)
2349+
{
2350+
reflected[i] = fwd[i] - 2.0 * dot * normal[i];
2351+
}
2352+
2353+
NormalizeVector(reflected, reflected);
2354+
GetVectorAngles(reflected, direction);
2355+
}
2356+
23322357
public Action Command_Beamer(int client, int args)
23332358
{
23342359
static float rate_limit[MAXPLAYERS+1];
@@ -2348,15 +2373,6 @@ public Action Command_Beamer(int client, int args)
23482373

23492374
for (int C = 20; C >= 0; --C)
23502375
{
2351-
/*
2352-
My code from tracegun.lua that I based this off of:
2353-
local ang = tr.Normal:Angle() // ( traceRes.HitPos - traceRes.StartPos ):Normalize()
2354-
ang:RotateAroundAxis(tr.HitNormal, 180)
2355-
local dir = ang:Forward()*-1
2356-
2357-
tr = util.TraceLine({start=tr.HitPos, endpos=tr.HitPos+(dir*100000), filter=players})
2358-
*/
2359-
23602376
TR_TraceRayFilter(startpos, direction, MASK_ALL, RayType_Infinite, TRFilter_NoPlayers, client);
23612377
TR_GetEndPosition(endpos);
23622378

@@ -2381,16 +2397,12 @@ public Action Command_Beamer(int client, int args)
23812397

23822398
if (!C) break;
23832399

2384-
SubtractVectors(endpos, startpos, direction);
2385-
NormalizeVector(direction, direction);
2386-
GetVectorAngles(direction, direction);
2387-
23882400
startpos = endpos;
23892401

23902402
float hitnormal[3];
23912403
TR_GetPlaneNormal(INVALID_HANDLE, hitnormal);
23922404

2393-
RotateAroundAxis(direction, hitnormal, 180.0);
2405+
ReflectAngles(direction, hitnormal);
23942406
}
23952407

23962408
return Plugin_Handled;

0 commit comments

Comments
 (0)