Using constraints to rotate a part around the player

I’m trying to make a part hover around the player and eventually rotate around the player at a fixed height and distance. I’m trying to implement this by having a part attached to the player’s humanoidrootpart using a hinge constraint, and then the rotating part is attached to that other part using a weld constraint. My issue is that currently, the hinge constraint lets the center part rotate around the x axis, when I want to rotate around the y. I tried setting the center part orientation to align the x axis by rotating 90 around the z axis, but the hinge constraint seems to reset this rotation everytime. Here’s the code I’m using so far:

        local OrbObject = Instance.new("Part")
	OrbObject.Massless = true
	local Character = Player.Character or Player.CharacterAdded:Wait()
	local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
	OrbObject.CFrame = HumanoidRootPart.CFrame * CFrame.new(0,0,-9)
	OrbObject.Parent = game.Workspace
	OrbObject.Anchored = false
	local OrbCenter = Instance.new("Part")
	OrbCenter.Massless = true
	OrbCenter.CFrame = HumanoidRootPart.CFrame
	OrbCenter.Orientation = Vector3.new(0,0,90)
	OrbCenter.Anchored = false
	OrbCenter.Parent = game.Workspace
	OrbCenter.Size = Vector3.new(2,1,3)
	OrbCenter.CanCollide = false
	self.OrbObject = OrbObject
	self.OrbCenter = OrbCenter
	self.Player = Player
	self.OrbConstraint = Instance.new("WeldConstraint")
	self.OrbConstraint.Part0 = self.OrbCenter
	self.OrbConstraint.Part1 = self.OrbObject
	self.OrbConstraint.Parent = self.OrbCenter
	self.OrbConstraint.Enabled = true
	local Attachment0 = Instance.new("Attachment")
	Attachment0.Parent = OrbCenter
	Attachment0.Name = "Attachment"
	local Attachment1 = Instance.new("Attachment")
	Attachment1.Parent = HumanoidRootPart
	Attachment1.Name = "Attachment"
	local CenterHinge = Instance.new("HingeConstraint")
	CenterHinge.Attachment1 = Attachment0
	CenterHinge.Attachment0 = Attachment1
	CenterHinge.Parent = OrbCenter

I would definitely use a Motor6D for that. You can easily change its C0 value to rotate around the character in relation to the HumanoidRootPart.

Can you provide a gif or video of any sort to show me where you’re at with this?

Here’s the current behavior: http://www.giphy.com/gifs/dUUBI3ThdV94ILbnkk

I’ll look into using Motor6D, thanks for the suggestion

The link doesn’t work! Getting a 404 error.

Apr-26-2020 14-01-58

1 Like

I was able to get the behavior I wanted using motor6d, thanks for the help!

1 Like