ive been trying to get this drone to go around this part without its orientation being changed, i have tried almost everything, and i need to know if this is even possible to do, heres my code
local part1 = game.Workspace.drones.drones["1"].PrimaryPart
local center = script.Parent["circle part 1"].CFrame
local radius = 6
local numParts = 1
local angleOffset = math.pi * 2 / numParts
local rotationSpeed = 2
local function updateOrbit()
local time = tick() * rotationSpeed
local angle = time % (math.pi * 2)
local pos1 = center + Vector3.new(math.cos(angle), 0, math.sin(angle)) * radius
part1.CFrame = pos1
end
game:GetService("RunService").Heartbeat:Connect(updateOrbit)
You are using the center part’s CFrame, which also contains the rotation of the center part. If you want to fix this issue you can either rotate the center part or change the drone’s position, rather than the CFrame.
local RunService = game:GetService('RunService')
local centerPart = workspace.OriginPart
local orbitingPart = workspace.OrbitingPart
local radius = 6
local rotationSpeed = 2
local pivotOffset = CFrame.Angles(
math.rad(90),
math.rad(0),
math.rad(0)
) --Edit the angles here to change the drone's orientation
local function updateOrbit()
local angle = time()*rotationSpeed
local offset = centerPart.Position+Vector3.new(math.cos(angle),0,math.sin(angle))*radius
orbitingPart.CFrame = CFrame.new(offset)*pivotOffset
end
RunService.Heartbeat:Connect(updateOrbit)
Modify the pivotOffset to change the orientation of the orbiting part (drone).
As far as I can see, the drone is maintaining the same orientation, so I’m assuming that you do not want that orientation right? If so, then try doing something like this:
local part1 = game.Workspace.drones.drones["1"].PrimaryPart
local center = CFrame.new(script.Parent["circle part 1"].CFrame.Position) -- has no rotational component
local rotation = CFrame.fromEulerAngles(0,0,0) -- (optional) use this to customize the drone's rotation
local radius = 6
local numParts = 1
local angleOffset = math.pi * 2 / numParts
local rotationSpeed = 2
local function updateOrbit()
local time = tick() * rotationSpeed
local angle = time % (math.pi * 2)
local pos1 = (center + Vector3.new(math.cos(angle), 0, math.sin(angle)) * radius) * rotation
part1.CFrame = pos1
end
game:GetService("RunService").Heartbeat:Connect(updateOrbit)