im kinda stuck i really confused on how to add 3d2d buttons when you click e on the 3d2d screen it gives u food like a vending machine
https://i.imgur.com/BfdPwrg.png
```lua
local POSITION = Vector(1, 2, 3)
local ANGLES = Angle(0, 0, 0)
local SCALE = 0.25
local ANGLES_ZERO = Angle(0, 0, 0)
function ENT:GetCursorPos(client)
local position = self:LocalToWorld(POSITION)
local angles = self:LocalToWorldAngles(ANGLES)
local hitPos = client:GetEyeTrace().HitPos
local pos = WorldToLocal(hitPos, ANGLES_ZERO, position, angles)
return pos.x / SCALE, pos.y / -SCALE
end
function ENT:Draw()
cam.Start3D2D(self:LocalToWorld(POSITION), self:LocalToWorldAngles(ANGLES), SCALE)
local cursorX, cursorY = self:GetCursorPos(LocalPlayer())
surface.SetDrawColor(255, 0, 255)
surface.DrawRect(cursorX - 2, cursorY - 2, 4, 4)
cam.End3D2D()
end
```
So `POSITION` and `ANGLES` are for positioning the 3D2D stuff and `SCALE` is to the size of a "pixel" in the 3D2D space.
Then, `ENT:GetCursorPos()` will give you the xy-coordinates of where the player is aiming at on the 3D2D screen. This is done by projecting the hit position of where the player is aiming at onto the 3D2D surface getting the appropriately scaled xy-coordinates of that projection.
But, this means that this only works well if the 3D2D surface is directly on top of the ent. So you can change the way `hitPos` is calculated if that isn't the case. From the screenshot above, it seems like the 3D2D stuff will probably be on the front face of the ent so it'll probably be fine.
To actually get buttons, you can define rectangles in the 3D2D surface and check if the cursor position is within a rectangle when they use the ent (`ENT:Use()`).
thank you so much if i have anymore problems or question ill reply thank you so much thou
A while ago I made some code for two versions of a slot machine. It works pretty much the same as Chessnut's code, but it might be a useful reference:
Fun/slotmachine.lua at master · MysteryPancake/Fun · GitHub
Fun/slotmachine2.lua at master · MysteryPancake/Fun · GitHub
Fun/slotmachine.lua at master · MysteryPancake/Fun · GitHub
Fun/slotmachine2.lua at master · MysteryPancake/Fun · GitHub
they confused me too much lmaoo anymore examples?
This gives you a way to figure out where the player is aiming at on a 3D2D screen. You can make "buttons" by drawing rectangles. Then, when the player uses the ent, you can check if the place they are aiming at is within a rectangle so it acts like a button press.
i have fixed the text but atm im trying to make a button remember the other post 3d2d buttons
so when i do that code
local POSITION = Vector(1, 2, 3)
local ANGLES = Angle(0, 0, 0)
local SCALE = 0.25local ANGLES_ZERO = Angle(0, 0, 0)
function ENT:GetCursorPos(client)local position = self:LocalToWorld(POSITION)
local angles = self:LocalToWorldAngles(ANGLES)
local hitPos = client:GetEyeTrace().HitPos
local pos = WorldToLocal(hitPos, ANGLES_ZERO, position, angles)
return pos.x / SCALE, pos.y / -SCALE
endfunction ENT:Draw()
cam.Start3D2D(self:LocalToWorld(POSITION), self:LocalToWorldAngles(ANGLES), SCALE)
local cursorX, cursorY = self:GetCursorPos(LocalPlayer())
surface.SetDrawColor(255, 0, 255)
surface.DrawRect(cursorX - 2, cursorY - 2, 4, 4)
cam.End3D2D()
end
it makes my model invisible literally my model disappears?
Put `self:DrawModel()` above the cam.Start3D2D stuff.
anyway to flip it so like its not like this if you know what i mean
http://prntscr.com/l2dscc
I just keep changing POSITION and ANGLES until it looks right.
how would i do the use i want to do it with networking with net.start and net.receive
local POSITION = Vector(1, 2, 3)
local ANGLES = Angle(0, 0, 0)
local SCALE = 0.25
local ANGLES_ZERO = Angle(0, 0, 0)
function ENT:GetCursorPos(client)
local position = self:LocalToWorld(POSITION)
local angles = self:LocalToWorldAngles(ANGLES)
local hitPos = client:GetEyeTrace().HitPos
local pos = WorldToLocal(hitPos, ANGLES_ZERO, position, angles)
return pos.x / SCALE, pos.y / -SCALE
end
function ENT:Draw()
self:DrawModel()
local Pos = self:GetPos()
local Ang = self:GetAngles()
cam.Start3D2D(Pos + Ang:Up() * 40 - Ang:Right() *3.9 + Ang:Forward() * 0.08, Ang + Angle( 0, 180, 90 ), 0.067)
local cursorX, cursorY = self:GetCursorPos(LocalPlayer())
surface.SetMaterial(donut_icon)
surface.SetDrawColor(255, 255, 255, 255)
surface.DrawTexturedRect(0,0,60,60)
cam.End3D2D()
cam.Start3D2D(Pos + Ang:Up() * 60 - Ang:Right() *3.9 + Ang:Forward() * 0.08, Ang + Angle( 0, 180, 90 ), 0.067)
local cursorX, cursorY = self:GetCursorPos(LocalPlayer())
surface.SetMaterial(coffee_icon)
surface.SetDrawColor(255, 255, 255, 255)
surface.DrawTexturedRect(0,0,60,60)
cam.End3D2D()
end
i tried using buttons instead of like textured rect and stuff but it would just duplicate buttons and lag out
but if i would of done buttons i would of did
function button:DoClick()
net.Start("string")
net.WriteString( k )
net.SendToServer()
You can call ENT.GetCursorPos in ENT.Use (you should probably move the definition of GetCursorPos to a shared.lua or something equivalent) Then, check if the cursor position is in the rectangle defined by a top-left coordinate of (0,0) and a width and height of 60.
If you don't mind a library, this one is pretty nice GitHub
i still do not understand what you are saying
this is what i got
function ENT:Use( activator, caller, 1 )
Sorry, you need to Log In to post a reply to this thread.