local ent
= NULL
hook.
Add(
"Think",
"Think_IntersectRayWithOBBExample",
function()
local ply
= LocalPlayer()
local trEnt
= ply:
GetEyeTrace().Entity
if (
IsValid( trEnt ) )
then ent
= trEnt
end
if (
!IsValid( ent ) )
then return end
local start
= ply:
GetShootPos()
local delta
= ply:
GetAimVector()
* 500
local endpos
= start
+ delta
local frac1, frac2
= util.
IntersectRayWithSphere( start, delta,
ent:
GetPos()
+ ent:
OBBCenter(),
ent:
OBBMaxs():
Length() )
if ( frac1 )
then
local intersect1
= LerpVector( frac1, start, endpos )
local intersect2
= LerpVector( frac2, start, endpos )
debugoverlay.
Axis( intersect1, angle_zero,
10,
0.01 )
debugoverlay.
Axis( intersect2, angle_zero,
10,
0.01 )
end
debugoverlay.
Sphere(
ent:
GetPos()
+ ent:
OBBCenter(),
ent:
OBBMaxs():
Length(),
0.01, frac1
!= nil and Color(
0,
255,
0 )
or Color(
255,
0,
0 ) )
end )