Hi guys! I’m Pew, a self-declared professional VFX artist on the Roblox platform.
Three days ago, I posted about my recreation of the infamous “Stoic Bomb”, and along with showcasing the effect, I also gave some insight on how it works.
I think that these kinds of posts could get me feedback whilst contributing to the community, so I decided that I’m going to make more posts like these!
In case you didn’t see the previous post, I recommend you go see it!
All that aside, let’s move on to the effect.
The main focus of this post will be the debris orbiting around the player. As you can see in the video, they can collide with walls and explode outwards.
Well, first, let’s see how to even make an orbit.
I’ll try to explain it based on this example code.
--// Settings
local dist = 10
local speed = 10
local phase = math.rad(math.random(-180,180))
--// Creating the part to be animated
local part = Instance.new("Part")
part.Parent = workspace
part.Position = Vector3.zero
part.Size = Vector3.one
part.Anchored = true
part.CanCollide = true
--// Animating the part with RunService
game:GetService("RunService").Stepped:Connect(function(t)
local X = math.sin(t * speed + phase) * dist
local Z = math.cos(t * speed + phase) * dist
local pos = Vector3.new(X, 2, Z)
part.Position = pos
end)
If you didn’t learn trigonometry yet (or just didn’t pay much attention in math class), here’s a quick explanation of why sine and cosine work for this.
Let’s look at a sine wave graph to start:
This graph represents a sine wave. To understand what’s going on, when you look at a number on the horizontal line, the red line represents the value of the sine of that number. If we use math.sin(time)
, we get a point on the red line. If we let time move forward and repeatedly set a part’s height to math.sin(time)
, it will move up and down smoothly.
The same goes for cosine, except it’s slightly offset (red - sine, blue - cosine)
We can use this logic to make the part’s X-position equal to the sine of time, and the Z-position the cosine of time, giving us a perfect orbit.
Let’s also briefly explain the settings.
- Distance multiplies the amplitude of the wave, making the diameter of the orbit larger.
- Speed multiplies the frequency of the wave, speeding up revolutions.
- Phase offsets our point, so multiple parts can orbit differently.
However, if you saw the video, you can see that there’s more going on than this.
So, what’s the secret sauce? Body Velocities or Linear Velocities are physics items that move objects in a straight line. Although Body Velocities are deprecated, I find them easier to work with, so I used those instead. I still recommend that you use Linear Velocities, though.
I’m not going to go too in-depth on this, so I’ll just explain how I do it briefly; you need to calculate a vector that points in the direction of the next position and apply it to your velocity object.
If you make the debris collidable, then it should be able to bounce off of walls like in the showcase video.
Also, the scatter is simply done by destroying the velocity objects and letting the parts run freely.
Did you think we were done? Nope, I have one more thing to cover!
The ability is extremely customizable. Check out these examples if you’d like!
Huge tornado:
Small base moveset attack:
External MediaThis all works thanks to the power of attributes! The concept is simple; you can add your own properties under an instance, modify them in the property tab, and then use them as variables in your code. This will also let you make adjustments during runtime. I don’t think there’s much else to say, so I’ll also give a few small tips and finish there.
-
Tip number 1:
If you want to make random values with attributes, don’t make two attributes (E.g, “MinDist”, “MaxDist”) but instead use a Number Range and use its Min and Max values. -
Tip number 2:
If you want to get real-number random values instead of integer random values, use the Random class and call:NextNumber(min, max)
on it. -
Tip number 3:
Don’t be like this
And PLEASE name your particles after what they represent (I’m too lazy to do it myself, but trust me, it makes it so much more organized)
Alright, that’s everything I’ve got to say.
I’d love to see feedback on this style of post, and the effect I made (I know, I know, there’s no camera shake, I couldn’t get it working). And, if you have any suggestions on what I should make next, I’d love to hear it!
(Also, if I made any mistakes, please correct me. I don’t want to spread misinformation.)
Thanks for reading!