How would I make a part follow an orbital path?

This is going to be an odd thing to break down.

To start, I want to make a part essentially orbit around a player’s HRP.

“What do you mean by orbit?”

I want to recreate the motion of the web throw in the Insomniac Spider-Man games.
Example: Web Throw

My problem as stated in the title is that I have little to no clue where to start and how I would go about this, any help would be appreciated. Thanks.

3 Likes

You can try using trigonometric functions to calculate the position of the part at each frame update.
For instance:

local part = -- Reference to the part you want to orbit around the player
local player = -- Reference to the player
local centerOffset = Vector3.new(0, 0, 0) -- Offset from the player's HRP to the center of the orbit
local radius = 10 -- Radius of the orbit
local speed = 1 -- Angular speed (radians per second)

local function updatePosition()
    local character = player.Character
    if not character then return end
    local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
    if not humanoidRootPart then return end
    
    local time = tick() * speed
    local angle = time % (2 * math.pi) 
    local positionOffset = Vector3.new(radius * math.cos(angle), 0, radius * math.sin(angle))
    local position = humanoidRootPart.Position + centerOffset + positionOffset
    part.Position = position
end

-- Update the position continuously
while true do
    updatePosition()
    wait() -- Yield to allow other processes to run
end

1 Like

Alright, I’ll try this out when I get home. Thanks.

This worked wonders, thank you so much.

1 Like

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