I need to make a 3d2d button as the title says. I googled a little while and found that:
[CODE]local isec = IntersectRayWithPlane( EyePos( ply ), Forward( EyeAngles( ply ) ), pos, trace.HitNormal )
if isec then
local ap = pos - isec
local ab = pos - tr
local ad = pos - bl
local ap_ab = Dot( ap, ab )
local ab_ab = Dot( ab, ab )
local ap_ad = Dot( ap, ad )
local ad_ad = Dot( ad, ad )
if 0 < ap_ab and ap_ab < ab_ab and 0 < ap_ad and ap_ad < ad_ad
and IsLineOfSightClear( ply, isec ) then --and if they have line of sight of the panel
--Do whatever you'd like, they're looking directly at the panel
end
end[/CODE]
So far, so good.
But it just causes lua erros if I try to use it.
For now it isn't a button...yet. It just changes it's color. I want that to work before a proceed with making it only work if I press "e" on it.
That's what I tried:
[CODE]
local ply = LocalPlayer()
[...]
surface.SetDrawColor( 255, 0, 0, 255 )
local pos = Vector(30,230)
local isec = util.IntersectRayWithPlane( EyePos( ply ), Forward( EyeAngles( ply ) ), pos, trace.HitNormal )
if isec then
local ap = pos - isec
local ab = pos - tr
local ad = pos - bl
local ap_ab = Dot( ap, ab )
local ab_ab = Dot( ab, ab )
local ap_ad = Dot( ap, ad )
local ad_ad = Dot( ad, ad )
if 0 < ap_ab and ap_ab < ab_ab and 0 < ap_ad and ap_ad < ad_ad
and IsLineOfSightClear( ply, isec ) then --and if they have line of sight of the panel
surface.SetDrawColor( 0, 255, 0, 255 ) --Do whatever you'd like, they're looking directly at the panel
end
surface.DrawRect( 30, 230, 270, 70 )
end[/CODE]
[CODE]
[ERROR] addons/loyality points and news screen/lua/entities/lp_screen/cl_init.lua:82: attempt to call global 'Forward' (a nil value)
1. unknown - addons/loyality points and news screen/lua/entities/lp_screen/cl_init.lua:82
[/CODE]
I don't understand while Forward is a nil value.
Tell me if you need to see more code to help me because the rest is pretty messy :smile: .
Use IntersectRayWithPlane(), run the returned vector through WorldToLocal, reverse your Y axis in the vector and check if the X and Y positions are within the bounds of the button
Also Forward isn't a default function, use EyeAngles():forward()
[QUOTE=AJ10017;50370662]Use IntersectRayWithPlane(), run the returned vector through WorldToLocal, reverse your Y axis in the vector and check if the X and Y positions are within the bounds of the button
Also Forward isn't a default function, use EyeAngles():forward()[/QUOTE]
I changed util.IntersectRayWithPlane to IntersectRayWithPlane() and now there is that error:
[CODE]
[ERROR] addons/loyality points and news screen/lua/entities/lp_screen/cl_init.lua:82: attempt to index global 'trace' (a nil value)
1. unknown - addons/loyality points and news screen/lua/entities/lp_screen/cl_init.lua:82
[/CODE]
I think I have to define trace but I don't exactly know how I should define it.
[QUOTE=|Shepherd|;50370826]I changed util.IntersectRayWithPlane to IntersectRayWithPlane() and now there is that error:
[CODE]
[ERROR] addons/loyality points and news screen/lua/entities/lp_screen/cl_init.lua:82: attempt to index global 'trace' (a nil value)
1. unknown - addons/loyality points and news screen/lua/entities/lp_screen/cl_init.lua:82
[/CODE]
I think I have to define trace but I don't exactly know how I should define it.[/QUOTE]
It was fine how it was
[QUOTE=AJ10017;50371594]It was fine how it was[/QUOTE]
I changed it back but the error persists
What should I do?
[CODE]
[ERROR] addons/loyality points and news screen/lua/entities/lp_screen/cl_init.lua:108: attempt to index global 'trace' (a nil value)
1. unknown - addons/loyality points and news screen/lua/entities/lp_screen/cl_init.lua:108
[/CODE]
instead of trace.HitNormal use the angle of the 3D2D instance and get its up vector using <angle>:Up()
[QUOTE=AJ10017;50377096]instead of trace.HitNormal use the angle of the 3D2D instance and get its up vector using <angle>:Up()[/QUOTE]
Could you tell me if I made any mistakes? At the moment there are no errors, it just does nothing.
[CODE]
function ENT:Draw()
local ply = LocalPlayer()
local player = LocalPlayer()
local dist = (ply:GetShootPos() - self.Entity:GetPos()):Length()
if (dist > 750) then return end
EntPos = self:GetPos()
self:DrawModel()
local ang1 = self:GetAngles()
ang1:RotateAroundAxis(self:GetAngles():Forward(), 90)
ang1:RotateAroundAxis(self:GetAngles():Up(), 90)
cam.Start3D2D(EntPos+(self:GetForward()*13)+(self:GetRight()*7.1)+(self:GetUp()*20), ang1, 0.05)
TestColor=Color(0,0,0,255)
surface.SetDrawColor( TestColor )
surface.DrawRect( 0, 0, 340, 360 )
surface.SetDrawColor( 255, 0, 0, 255 )
local pos = Vector(30, 230)
local isec = util.IntersectRayWithPlane( EyePos( ply ), EyeAngles( ply ):Forward() , pos, ang1:Up() )
--print(ang1)
if isec then
local ap = pos - isec
local ab = pos - tr
local ad = pos - bl
local ap_ab = Dot( ap, ab )
local ab_ab = Dot( ab, ab )
local ap_ad = Dot( ap, ad )
local ad_ad = Dot( ad, ad )
if 0 < ap_ab and ap_ab < ab_ab and 0 < ap_ad and ap_ad < ad_ad
and IsLineOfSightClear( ply, isec ) then --and if they have line of sight of the panel
surface.SetDrawColor( 0, 255, 0, 255 )--Do whatever you'd like, they're looking directly at the panel
print(isec)
end
end
surface.DrawRect( 30, 230, 270, 70 )
-- [...]
[/CODE]
Sorry, you need to Log In to post a reply to this thread.