How to make a part spin and levitate

In my game I have items that that can be collected. I would like it so that they could spin but with a levitating effect. How would I do this?

1 Like

If you want to make the parts spin in place without moving then you could use BodyPosition and BodyAngularVelocity. You will have to unanchor them though.

If you want them to move up and down you can use TweenService in a script to slowly move them up and down on a loop.

Need not use TweenService for that , you change the Position of the BodyPosition which will move the part based on the force of the BodyPosition.

How do I do it though? Do I need to make a script?

You mean adding BodyPosition and BodyAngular Velocity or the Movement of the part? For the movement you need a script , adding can be done manually or via script.

I want to know how I can make a mesh part spin and move up and down.

Just add a BodyAngularVelocity to the Part and set the Velocity so it rotates in a certain velocity , and add a BodyPosition . In a script change the position of the BodyPosition in a loop so that it moves up and down.

1 Like

Does the part need to be unanchored?

It can be unanchored you can increase the MaxForce/Torque of the BodyPosition so it levitates.

Iā€™d suggest looking into the new constraints, such as torque, align position, orientation, etc as these replace the old body movers

How do I make it so that is levitates above where it is placed? image Because it moves far up.

BodyPosition.Position = Gem.Position + Vector3.new(0,15,0) -- Change 15 for higher altitiude

1 Like


Is that how it should be set up?

No , you need to define BodyPosition and Gem

1 Like

like this?

local BodyPosition = game.Gem.BodyPosition
local Gem = game.Gem

BodyPosition.Position = Gem.Position + Vector3.new(0,15,0) -- Change 15 for higher altitiude

Yeah , you can use script.Parent but this is fine too.

1 Like

This definitely will work but another way is using, as you mentioned, tweenservice, but another extremely useful, controllable way is a renderstepped looped in a local script. This will allow you to use math.sin() for the Y position and adjust the levitation speed and rotation speed differently.

1 Like

Thats a really good way too , but I doubt whether the person asking for help is advanced enough to do that.

Btw you gotta use a loop so that it levitates.

Yep, make sure to do it in a local script if you only intend it to be purely for aesthetics and not for gameplay purposes, or else the server will lag.

Here is a version which uses CFrames with the same math.sin() concept mentioned to do it on the server just insert it into a script in an anchored part and watch it go:

Here is the code:

local part = script.Parent

local RunService = game:GetService("RunService")

--controls how fast it spins clockwise:
local degreesPerSecondYAxisRotation = math.rad(90)

--Random numbers related to sin, mess around with it
local A = 0.1
local B = 7
--every frame, after physics stuff happens run this code:
RunService.Heartbeat:Connect( function(step)
	--Makes it rotate clockwise
	part.CFrame *= CFrame.Angles(0,-degreesPerSecondYAxisRotation*step,0)
	
	--Make it go up and down cyclically
	local x = tick()--time as x
	local y = A*math.sin(B*x)--el math equation same as y = A * sin(Bx) use a graphic software like desmos to see how that looks like and what happens if you change A and B.
	part.CFrame *= CFrame.new(0,y,0)
end)
6 Likes