How would I make this spin around my character?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? I wan’t to know how I can make this little orb rotate around my character and look at the HumanoidRootPart while doing so

  2. What is the issue? I don’t know what to do as I am not that familiar with what to do here. Here’s the code I got:

local runservice = game:GetService("RunService")
local flayon = game:GetService("ReplicatedStorage").Flayon

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		if player.Name == "AVCOIL5" then
			flayon.Parent = char
			while true do
				task.wait(.01)
				flayon.Head.Position = char.Torso.Position + Vector3.new(0,0,5)
				local lookAt = CFrame.lookAt(flayon.Head.Position, char.PrimaryPart.Position)
				local aimTweenInfo = TweenInfo.new(.1)
				local lookAt = CFrame.lookAt(flayon.Head.Position, char.HumanoidRootPart.Position)
				local aimTween = game:GetService("TweenService"):Create(flayon.Head, aimTweenInfo, {["CFrame"] = lookAt})
				aimTween:Play()
			end
			--game:GetService("ReplicatedStorage").Flayon.Head
		end
	end)
end)
  1. What solutions have you tried so far? I looked on DevForum posts and found nothing.

Currently, I only have it so the orb changes position to my HumanoidRootPart every .01 seconds, but I want it so it rotates around my character. Any ideas?

I would suggest you use instance.new zo create a hingeconstraint, then create the first attachment inside the part with the hinge and the other attachment inside the orb. Then just set the angular velocity to your liking! Also dont forget setting the orb to massless or you will get fling!

Dont forget to mark this as solution if it helped!

:slight_smile:

1 Like

Can you write the code as i’m still having problems with this? I tried it, and I am getting flinged so I know i might be doing it wrong. If you could write some of the code that would be pretty nice!

If you open the chat, the part will appear infront of you

1 Like

I am not letting anyone in team create as I am a solo dev.

To write code, use 3 of the symbols below a line, write code below that line, then below the final line of the 3 symbols again. it should look something like

script.Parent.IAmShowingYouSomethingHere

image

To make the orb rotate around your character, you will need to update its position using a combination of CFrame s and TweenService . Here is an example of how you can do it:

  1. First, define the radius of the orbit and the starting angle of the orb. You can do this by setting the initial position of the orb to be a certain distance away from the character’s position, using a CFrame :
local radius = 5
local angle = 0
local initialPosition = char.PrimaryPart.Position + Vector3.new(radius * math.cos(angle), 0, radius * math.sin(angle))
flayon.Head.Position = initialPosition
  1. Next, create a loop that updates the position of the orb every frame. Inside the loop, increment the angle by a small amount (e.g. 0.01 radians) and use it to calculate the new position of the orb. You can do this by creating a new CFrame that translates the orb to the new position:
while true do
  task.wait(0.01)
  angle = angle + 0.01
  local newPosition = char.PrimaryPart.Position + Vector3.new(radius * math.cos(angle), 0, radius * math.sin(angle))
  local newCFrame = CFrame.new(newPosition)
  flayon.Head.CFrame = newCFrame
end
  1. To make the orb look at the character as it orbits, you can use the TweenService to smoothly interpolate between the orb’s current orientation and the desired orientation. First, create a TweenInfo object to control the duration and easing of the interpolation:
local aimTweenInfo = TweenInfo.new(0.1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
  1. Then, create a CFrame that represents the desired orientation of the orb (i.e. looking at the character’s HumanoidRootPart ). You can do this using the CFrame.lookAt function:
local lookAt = CFrame.lookAt(flayon.Head.Position, char.HumanoidRootPart.Position)
  1. Finally, create a new Tween using the TweenService and play it:
local aimTween = game:GetService("TweenService"):Create(flayon.Head, aimTweenInfo, {["CFrame"] = lookAt})
aimTween:Play()

You can combine these steps into the following script:

local runservice = game:GetService("RunService")
local flayon = game:GetService("ReplicatedStorage").Flayon

game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
if player.Name == "AVCOIL5" then
flayon.Parent = char
while true do
task.wait(.01)
local angle = 0.1 -- The angle to rotate by each frame
local radius = 5 -- The radius from the character to rotate the orb around
local orbit = CFrame.new(char.Torso.Position) * CFrame.Angles(0, angle, 0) * CFrame.new(0, 0, radius)
flayon.Head.Position = orbit.p
local lookAt = CFrame.lookAt(flayon.Head.Position, char.HumanoidRootPart.Position)
local aimTweenInfo = TweenInfo.new(.1)
local aimTween = game:GetService("TweenService"):Create(flayon.Head, aimTweenInfo, {["CFrame"] = lookAt})
aimTween:Play()
end
end
end)
end)

This. is. awesome! It works. But my orb isn’t looking at the character and it’s more to my head Y position. I will still mark yours as sollution if you don’t know what to do next, but here’s my code and video:

local runservice = game:GetService("RunService")
local flayon = game:GetService("ReplicatedStorage").Flayon

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		if player.Name == "AVCOIL5" then
			flayon.Parent = char
			while true do
				task.wait(.01)
				local radius = 5
				local angle = 0
				local initialPosition = char.PrimaryPart.Position + Vector3.new(radius * math.cos(angle), 0, radius * math.sin(angle))
				flayon.Head.Position = initialPosition
				while true do
					task.wait(0.01)
					angle = angle + 0.01
					local newPosition = char.PrimaryPart.Position + Vector3.new(radius * math.cos(angle), 0, radius * math.sin(angle))
					local newCFrame = CFrame.new(newPosition)
					flayon.Head.CFrame = newCFrame
					
					local aimTweenInfo = TweenInfo.new(0.1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
					local lookAt = CFrame.lookAt(flayon.Head.Position, char.HumanoidRootPart.Position)
					local aimTween = game:GetService("TweenService"):Create(flayon.Head, aimTweenInfo, {["CFrame"] = lookAt})
					aimTween:Play()
				end
			end
		end
	end)
end)

Vid:


(sorry for the bad vid, I am kind of in a rush so i’m using Bandicam.)

You can try separating the logic for updating the position of the orb and making it look at the character into two different loops. You can use the TweenService to smoothly interpolate the orientation of the orb over time, so that it looks more natural as it orbits.
Try this

local runservice = game:GetService("RunService")
local flayon = game:GetService("ReplicatedStorage").Flayon

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		if player.Name == "AVCOIL5" then
			flayon.Parent = char
			while true do
				task.wait(.01)
				local radius = 5
				local angle = 0
				local initialPosition = char.PrimaryPart.Position + Vector3.new(radius * math.cos(angle), 0, radius * math.sin(angle))
				flayon.Head.Position = initialPosition
				while true do
					task.wait(0.01)
					angle = angle + 0.01
					local newPosition = char.PrimaryPart.Position + Vector3.new(radius * math.cos(angle), 0, radius * math.sin(angle))
					local newCFrame = CFrame.new(newPosition)
					flayon.Head.CFrame = newCFrame
					
					local aimTweenInfo = TweenInfo.new(0.1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
					local lookAt = CFrame.lookAt(flayon.Head.Position, char.HumanoidRootPart.Position)
					local aimTween = game:GetService("TweenService"):Create(flayon.Head, aimTweenInfo, {["CFrame"] = lookAt})
					aimTween:Play()
				end
			end
		end
	end)
end)

Im still getting the same issue as before. I will try using multiple position stuff tho, and if that works ill mark yours as sollution

EDIT: I got it working! all I had to do was make aimTweenInfo very constant and not switch position by using CFrame, but just position.

Btw just winished the orbs… you wanna see them?

1 Like

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