Urgent help with positions and orientations


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)

bump because i need this fast.

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.

i have tried the drone just glitches could you show an example?

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)

your script seems to work but the angle seems off, when i put for ex 0, -90, -90 and go in game, and go check the orientation its 0, -116.62, -116.62

CFrame angles are not the same values as part orientation.

how do i calculate cframe then

how do i calculate cframe angles*

You can get the drone’s rotation and use it when you need it:

local rotation = CFrame.Angles(part1.CFrame:ToOrientation())
1 Like

thank you so much, fixed the problem

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.