Making a part rotate around another part

How do I make it so that Part A rotates around Part B in a natural manner and whatever it is that Part A is doing, it doesn’t have an influence on Part B. So like, if Part B moves forward so does Part A while also spinning around it. But whatever Part A does, it doesn’t affect Part B.

4 Likes

Just a HingeConstraint | Roblox Creator Documentation with an Attachment | Roblox Creator Documentation on part B, and the Attachment for Part A in the same location causing the hinge to spin there. You can change the Attachment | Roblox Creator Documentation of Part A to be at the hinge so when the HingeConstraint | Roblox Creator Documentation is set to Motor it will rotate around PartB.
Making Part A not influence Part B could be done by making its Massless Property true.
If you make Part A CanCollide off then it won’t hit other items in the game and cause Part B to be moved, or just set the MotorMaxTorque to a low value so that Part A will rotate around but just bump against other Parts, but not be spun with enough force to affect Part B.

2 Likes

Will this work if both parts aren’t in contact?

This code below should solve your question: (note that A is the center and B is the revolving part)

local RS = game:GetService("RunService")

local a = workspace.PartA
local b = workspace.PartB

local speed = .5

local mag = 0
local angle = 0

RS.Heartbeat:Connect(function(dt)
	mag = (a.Position-b.Position).Magnitude
	angle = (angle + dt * (math.pi * speed)) % (2 * math.pi)
	b.CFrame = a.CFrame * CFrame.new(math.cos(angle) * mag, 0, math.sin(angle) * mag)
end)

This is an altered form of code grabbed from a previous post asking a similar question: Orbit Solution

Simply put, this code uses sine and cosine to construct a circle based on dt (deltatime).

6 Likes

You can put Attachments in at whatever distance/orientation you want!

1 Like

In the end I used a simple weld constraint and it worked perfectly, to whoever has the same question as I had: Just instance a weld constraint, and spin the center part using BodyAngularVelocity and set it’s MaxForce to math.huge. Thank you to everyone who replied though!

6 Likes

But doesn’t that affect Part B by making it spin too?
I thought you wanted Part B to be able to move around (like on a car or a player) without being rotated.

1 Like

Part B is actually supposed to be a tornado, and Part A the humanoid root part of a character. Part B is already spinning.

2 Likes