This is an implementation of an electric arc effect for Roblox games. It draws electricity sparks between two static or moving points, and you can change various properties such as the color, the number of arcs, whether it is enabled/disabled, etc.
Courtesy of user @AllYourBlox for the original implementation of the algorithm that produces the line segments for the arcs (click here). The original code has been modularized, refactored and optimized for ease of use and more widely applicable use.
(Some details on differences in implementation from original)The original code manipulated many neon parts every frame which was not optimal due to the work it takes for the engine to update the position and size of baseparts. This version draws the line segments that represent the arcs through ImageHandleAdornments with the texture of a glowing line segment. Please note that this is still somewhat on the performance-heavy side and may be an overkill kind of implementation for such an electricity effect, but the library does include auto-throttling and other tricks to make sure the frame rate stays as high as possible and no effort is wasted updating effects that are far away compared to those closeby.
See here for a visual example: (video)
Model file with just the module: Arc.rbxm (12.7 KB)
Example place from the video above: ElectricArc.rbxl (31.9 KB)
Also available in the Library as a model: https://www.roblox.com/catalog/02770378782/redirect
The following listing shows how some of the most important API is used to make the effects happen in a game.
local Arc = require(game.(...).Arc) -- Make an arc between two static points with default colors: local arc1 = Arc.new( Vector3.new(10, 10, 0), Vector3.new(-10, 10, 0) ) -- Make a dynamic arc linked between two (moving) attachments: local arc2 = Arc.link( workspace.ArcStart.Attachment, workspace.ArcEnd.Attachment ) -- Make an arc that is green: local arc3 = Arc.new( Vector3.new(10, 10, 0), Vector3.new(-10, 10, 0), Color3.new(0, 1, 0) ) -- Make a blue one with 12 arcs (instead of default 6) with segments that are half as wide as normal: local arc4 = Arc.new( Vector3.new(10, 10, 0), Vector3.new(-10, 10, 0), Color3.new(.5, .5, 1) -- cyan Color3.new(1, 1, 1), -- top color (not important here) 12, -- number of arcs 0.5 -- fatness multiplier (half of normal) ) -- Change various properties while it is running: arc1:SetColor(Color3.new(1, 0, 0)) -- make it red arc1:SetRange(Vector3.new(20, 10, 0), Vector3.new(-20, 10, 0)) -- update points arc2:SetEnabled(false) -- toggle off temporarily arc3:SetCFrame(arc3:GetCFrame() + Vector3.new(0, 5, 0)) -- move up by 5 studs arc4:SetFatnessMultiplier(2) -- twice as fat as default now -- Cleanup arcs: arc1:Destroy() arc2:Destroy() arc3:Destroy() arc4:Destroy()
Please refer to the Github repository for the full API listing:
This library is freely available for use in your projects under the MIT license. (See Github repository if you need details)
Credit to @AllYourBlox for open-sourcing the algorithm that produces the line segments for the arcs, which was edited and optimized for this implementation.
Show Me Your Moves™
If you do anything cool with this, let me know in a reply here, or on Twitter via https://twitter.com/buildthomasRBX
Let me know also if you have any requests or suggestions regarding this effect or the code. (you can also file issues / pull requests on the repository)