Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CS2TraceRay/CS2TraceRay.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.316" />
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.320" />
</ItemGroup>

<ItemGroup>
Expand Down
23 changes: 23 additions & 0 deletions CS2TraceRay/Class/TraceRay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,27 @@ public static CGameTrace TraceHull(Vector start, Vector end, CTraceFilter filter

return *_trace;
}
/// <summary>
/// Performs a line trace (raycast) from the player's eye position to a specified destination, using the given trace mask.
/// </summary>
/// <param name="player">The player controller whose eye position is used as the trace start point.</param>
/// <param name="destination">The world-space destination position to trace towards.</param>
/// <param name="mask">Trace mask flags as a ulong, specifying which types of surfaces or entities to consider during the trace.</param>
/// <returns>
/// Returns a <see cref="CGameTrace"/> structure containing the result of the trace operation, including hit information such as the entity hit, surface details, and impact position.
/// If the player's pawn or its origin is unavailable, returns a default (empty) <see cref="CGameTrace"/>.
/// </returns>
public static CGameTrace GetGameTraceByEyePosition(
CCSPlayerController player,
Vector destination,
ulong mask
)
{
var pawn = player.PlayerPawn?.Value;
if (pawn is null || pawn.AbsOrigin is null)
return new CGameTrace();

var start = pawn.AbsOrigin + new Vector(0, 0, 64);
return TraceShape(start, destination, mask, 0ul, pawn.Handle);
}
}
2 changes: 1 addition & 1 deletion CS2TraceRayExample/CS2TraceRayExample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.316" />
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.320" />
</ItemGroup>

<ItemGroup>
Expand Down