Help With Circular Flying Script

Hi everyone. Recently I’ve been trying to figure out an issue which is seemingly simple, but I don’t know where to start. I’ve included the following screenshot to illustrate my point.

I want to script a single bird mesh to smoothly fly clockwise in a circle on a loop. The image isn’t to scale, because I want the bird to fly around ten studs from center.

I have searched for solutions, but I have only found scripts for items spinning and revolving, not flying in a circle around a central point. I’d appreciate any help or tips for this specific issue.

Bird2

Well ill give you a simple solution!

You can make a part that’s spinning with a WeldContstraint in it.

For Example:
image

How to set it up:
image
The weld:
image

Code:

while true do
	script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0, 0, 0) * CFrame.fromEulerAnglesXYZ(0, 00.1, 0) 
	wait()
end

Result:

Hope This Works Well!

5 Likes

Wow, that was a full tutorial, and he is correct. The studs of the part would be twice distance of what you need.

2 Likes

This may be a bit more elegant than adding a weld constraint and everything, since it won’t add unnecessary physics/attachment overhead

References: RunService | Documentation - Roblox Creator Hub
CFrames | Documentation - Roblox Creator Hub

local birdPart = workspace.MyBirdMeshPart
local centerPoint = Vector3.new(0,0,0)
local distanceFromCenter = 10
local birdSpeedFactor = 1

local maxHeight = 1.5
local height = 0
local heightDirection = 1

local RunService = game:GetService("RunService")

birdPart.CFrame = CFrame.new(centerPoint + Vector3.new(distanceFromCenter,0,0))
birdPart.CFrame = birdPart.CFrame*CFrame.Angles(0,math.rad(90),0)  
-- w/ trial and error try 0,90,180, and 270 here to see which direction your specific mesh needs to face

local centerCf = CFrame.new(centerPoint)

RunService.Heartbeat:Connect(function()
    -- get a cframe relative to the center cf that does not change
    local relativeBirdCf = centerCf:ToObjectSpace(birdPart.CFrame)
    -- 'rotate' the center cf, and then from the result, convert our relative cf back to its original world position, but now it'll be rotated as if it were welded to the center cf when it was rotated
    local rotatedBirdCf = (centerCf*CFrame.Angles(0,.01*birdSpeedFactor,0)):ToWorldSpace(relativeBirdCf)
   
    birdPart.CFrame = rotatedBirdCf

    --i added this for fun  :) 
    height += heightDirection*maxHeight/15
    if height > maxHeight then
       heightDirection = -1
    elseif height < -maxHeight then
        heightDirection = 1
    end 
     -- basically, set bird cframe to original height + calculated height offset
     -- this will give the bird and effect like it's "hovering" up and down as it circles around the center point
    birdPart.CFrame = birdPart.CFrame + Vector3.new(0,centerCf.y + height - birdPart.CFrame.y,0)
end)

2 Likes