Hello Guys,
Today I’ve continued my “draw polygons on GUI” demo project.
I think, this step is quite interesting
https://www.roblox.com/games/9072961285/Neon-GUI-demo-Particles-on-2d-GUI
This demo can do a lot:
- first of all, it DRAWS PARTICLE EMITTERS ON THE SCREENGUI - or is it just a trick?.. check it out!
- dynamically changes the mouse cursor depending on the current action
- 5 buttons to control the drawing (on/off drawing, reset drawing, hide lines, hide markers)
As always, you can edit the script in Studio, all codes are free to use.
Note: this is not a real OOP kind of script, rather a “I want to do it, because I can do it”. The 3 scripts sum up to 500 lines, so it is not a “one-function” code any more, but I think it is still quite easy-to-read.
All objects and scripts are located in StarterGui\neonGui - no other folder is used.
Here I highlight the simplified function that draws the line on the GUI with particles - as you may guessed, this is a hidden 3D “Part” object stick to the camera:
function addLine3D(m1:Vector3, m2:Vector3)
local ray1 = Camera:ScreenPointToRay(m1.X, m1.Y, 1)
local ray2 = Camera:ScreenPointToRay(m2.X, m2.Y, 1)
local r1 = ray1.Origin + ray1.Direction
local r2 = ray2.Origin + ray2.Direction
local line3D = Instance.new("Part")
local XSIZE:number = .001 -- no need any visible depth
local ZSIZE:number = .02 -- this is the width of the part facing to the camera
line3D.CFrame = CFrame.new((r1+r2)/2, r1) * CFrame.Angles(math.pi/2, 0, 0)
line3D.Size = Vector3.new(XSIZE,(r2-r1).Magnitude, ZSIZE)
...
Notes:
- m1 and m2 are GUI pixel positions, e.g. as coming from Mouse object.
- line3D is not visible (Transparency = 1).
- Particle emitter is parented to this hidden line3D object, that’s how it works.
Find the whole function and more in the demo!
May you like this concept (or may not), drop a line below!