I’m trying to create a Lightning effect similar to the one above - I’ve seen other posts similar but none with any resolutions that are plausible.
I’m looking to make the Lightning to travel from PointA to PointB in a similar effect ((Or smoother, if possible)) but also have the ability to control the speed of which it travels ((Not depending on distance.))
there’s a very famous module resource in the resources tab. Try searching Lightning Bolt in community resources. It’s very widely used and looks far better than the video!
If you want to make that specific example yourself, I wouldn’t be surprised if it simply takes the starting point, picks a random coordinate in some maximum radius around it, and offsets it in the direction of the target. Set this as the second point. Make a part between the first and second point. Then rinse and repeat from the second point*, etc, until you get close enough to the target. Just add a fading color, and destroy the parts after some time. You could even smooth it out with a tween on the front and back parts sizes, but this example doesn’t seem to have it. Can’t guarantuee this is how it was done and if it would look like this, it’s just my guess. Frankly my own attempts at cool-looking lightning got either very inefficient or simply premade with 2d assets, but as mentioned there should be good plugins that solved this problem already.
*actually probably best to project this point back to the line between start and target, before picking a random coordinate nearby, to prevent drift.
I just spent an hour (and now an additional 30 minutes or more creating this reply) creating this instead of working on my VR Hands game cause this is just some really cool effects but anyways. What I first did was have 2 points (PointA as the starting point and PointB as the finishing point). The green glowing brick will represent the start position and the red glowing brick will represent its finish (or target) position. I then created a part and named it projectile which will be represented as the yellow glowing brick. I then tweened the position of the projectile to the target position. While the projectile is moving, I created random nodes for positioning/"raying" the lightning beams start and end points/positions by doing the code down below (which should be in a loop). The nodes will be represented as blue glowing bricks;
local Spacing = 8
Node.Position = Projectile.Position + Vector3.new(math.random(-Spacing,Spacing),math.random(-Spacing,Spacing),math.random(-Spacing,Spacing))
What you should have is something like this now;
After creating that you must do some ray (maybe, rays could work but I didn’t use rays), math (I know, math is ew-bad-hard ), and table (for ordering nodes and beams in order) things which I cannot explain because I’d be so horrible. But the code down below is what I used to connect those beams.
Wow that’s really cool! With another lerp you can even do without the projectile and tween. Your version looks a lot like the original, certainly better than what I suggested.