I understand that I could have used animation, but I took a couple weeks off of scripting and kind of forgot how to? Anyways, I could use some help using CFrame to make a part move around in a circle (not rotation). If you could edit this code to help me, it would help a lot, thanks.
for i = 1,math.huge do p.CFrame = plr.Character.Head.CFrame + Vector3.new(i,5,i) p.Orientation = Vector3.new(i,5,0) wait(.05) end
I am adding this to my code for design, i tried a for i = 1,math.huge loop and made it move the X and Z vectors to i every loop. It only fly's off into space. I wanted to try using rotation to make it move forward where the part is facing, but I knew for a fact it wouldn't work.
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:
-- time (in seconds) it takes to complete one full rotation 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:
wait() / cycle_duration
wait()
interval. Ideally, you'll want to do this locally using RunService.RenderStepped:Wait()
or something of sorts.(wait() / cycle_duration) * 360
math.rad((wait() / cycle_duration) * 360)
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!
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 -- time (in seconds) it takes to complete one full rotation (this controls speed) local cycle_duration = 5 -- how many studs the orbiting part is away from it's center local radius_offset = 10 -- some reference to a part that the other part will orbit around local center_part = workspace.Part while true do -- creating a variable for the angle increment 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
center_part
local angle_inc = math.rad((rstep:Wait() / cycle_duration) * 360)
RunService.RenderStepped:Wait()
instead of just wait()
as mentioned before.CFrame.new(0, 0, radius_offset)
radius_offset
studs. You are also free to modify the X and Y axes to offset the satellite differently as well.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.
This is the easiest way as far as I know:
while wait() do p.CFrame = CFrame.new(plr.Character.Head.CFrame*CFrame.Angles(math.rad(p.Orientation.X+1),math.rad(p.Orientation.Y+1),math.rad(p.Orientation.Z+1))) end
--That should do the same thing as your script and hopefully work.