Whenever you're simulating the movement or animation of something, it should always be a function of time. In other words, "where should this part be t seconds from now?" or "how should this object look t seconds from now?"
This way, instead of basing your animation on a constant "step" or "speed" when you have inconsistent intervals, you base the animation on what the intervals should add up to (the time it takes to complete.) In turn, this does define the speed the animation will run in, while making it a lot smoother.
Here's an example using your situation:
local cycle_duration = 5
while true do
part.CFrame = part.CFrame
* CFrame.Angles(0, math.rad((wait() / cycle_duration) * 360), 0)
end
The math can be explained as follows:
Of course, the axis you wish to rotate around and the speed at which you want it to rotate is left for you to easily configure. For faster rotations, lower the cycle_duration to a shorter amount of time. For slower rotations, lengthen it. If you want to rotate around the x-axis, then put the angle increment in CFrame.Angles(x, 0, 0). If you want to rotate around the y-axis, put the angle increment in CFrame.Angles(0, x, 0). You get the idea.
Hope this helped!
Edit
The solution you're looking for isn't all that different from what was provided above, but there are some changes worth noting that I'll cover.
Here is the modified code:
local RunService = game:GetService("RunService")
local rstep = RunService.RenderStepped
local cycle_duration = 5
local radius_offset = 10
local center_part = workspace.Part
while true do
local angle_inc = math.rad((rstep:Wait() / cycle_duration) * 360)
part.CFrame = center_part.CFrame
* CFrame.Angles(0, angle_inc, 0)
* CFrame.new(0, 0, radius_offset)
end
Here is an explanation of the modifications:
radius_offset
- This determines how far away the part is from the object it's orbiting around.
center_part
- This should be the central part that the satellite part is orbiting around.
local angle_inc = math.rad((rstep:Wait() / cycle_duration) * 360)
- This is just a clean-up of the previous code, and also implementing
RunService.RenderStepped:Wait() instead of just wait() as mentioned before.
CFrame.new(0, 0, radius_offset)
- This is the CFrame that offsets the satellite part on the Z axis by
radius_offset studs. You are also free to modify the X and Y axes to offset the satellite differently as well.
Expected Result
That should cover everything. Again, hope this helps. If this still isn't what you were looking for, let me know and I'll try to clarify.
5 comments
Note that p is a variable for the part I am using, and plr is the targetted player in game:GetService'Players'.
ScriptGuider made a good answer for this type of question, it uses the same logic as what I think you're asking. https://scriptinghelpers.org/questions/25441/rotating-around-a-point
I appreciate the reference, pid! However, I would do it slightly differently these days. I've posted an answer that I believe to be a better version of my old answers on the topic on this post.
waitholdonaminute, do you get notified for referencing links, or are u just rllllly active still
Just happened to be a coincidence