How would I make a part spin very smoothly

Hi everyone,

How would I make a part spin very smoothly because every time I code it to spin, it spins but not very smoothly.

I have seen some people use an Animation to spin parts instead of using CFrames. Should I use an Animation to spin my part? Is it better?

8 Likes

tbh it’s not hard

here is an example of your question

Formula

script.Parent.CFrame = script.Parent.Orientation*CFrame.Angles(0,math.pi/15,0)

Neither way you can use this with RunService and call it

Can you give us this laggy part “CODE”

6 Likes

Personally, I am a huge fan of using motor6d, which is basically a cframe motor. There’s several plugins which can assist you in this creation of these, I suggest looking into it.

4 Likes

There are multiple ways of doing this as @SalientViper says with Motor6D, but also with TweenService, given the location by CFrame. However, if you want the player to stand on the spinning part without falling off, I wouldn’t recommend using TweenService.

2 Likes

Part.Orientation = Vector3.new(0,tick(),0)

Put the line above inside a render step connection.

you can multiply tick to make it slower or faster.

2 Likes

Isnt BodyAngularVelocity also a thing you can use?

2 Likes

I wouldnt rely on physics to be honest.

3 Likes

The issue with setting it manually is that if you set it on the server, there will be visible “lag” to players.

If you use a bodymover, there is an element of prediction that helps to make it smooth to all clients.

Similarly, TweenService propagates the tween to all clients and makes it smooth locally.

This has the added benefit of better visual physics for players as their physical position is calculated on the client.

3 Likes

Why not do what I suggested to do on the client

1 Like

Depends what their use case is. I think the easiest thing is to make no assumptions until the original poster says the use case. Or state all assumptions alongside your solution.

A situation-specific assumption without limitations and assumptions stated next to it can lead beginners down the wrong path easily.

The spinning object may need to interact with server-owned physical objects as well as the character and client-owned objects. I’ll wait to see if @Soggy_Bomb has any specific use case and scenarios that it needs to cover.

2 Likes

while true do
script.Parent.Orientation = script.Parent.Orientation + Vector3.new(0, 1, 0)
wait()
end

Is this what you looking for?

6 Likes
local part = script.Parent -- the part
local partspeed = 0.05 -- speed of the spin

while task.wait() do

part.CFrame = part.CFrame * CFrame.Angles(0,partspeed,0) -- the spin of the part

end
30 Likes

Use hingeconstraints, easiest way to do that. You can control the speed, torque, and rate of acceleration all in one place with no scripting required.

1 Like

reduce the increment it rotates by and the wait time by the same factor e.g if your doing wait(21) and rotate by 7 degrees each loop, reduce it to rotate by 1 and wait 3. or you could use the TWEEN service or the lerp service which is used for smooth movements

2 Likes

Using hingeconstraints you can make it spin very fast smoothly, reaching very high rpms, no scripting required. Torque, rate of accele/deceleration are all controllable right in the same window. With hingeconstraints you can also make it a servo type of motor which will automatically align a part with a certain orientation. Or you could just use it as a hinge where it spins freely along the axis it is attached to. hope this helped. hingeconstraints work much better than scripting, and you can actually use parts attached to hingeconstraints in the physics system, vs cframe scripting which does not actually change the velocity of the part and thus it can not correctly interact with other parts

1 Like

you can just tween orientation or just using CFrame.lerp

2 Likes

Just tween it

2 Likes

You could probably Tween it to rotate 90 degrees and keep playing the Tween infinitely.

Here is an example:

local TweenService = game:GetService("TweenService")
local Part = game.Workspace.Part

local Info = TweenInfo.New(
     1,
     enum.EasingStyle.Sine,
     enum.EasingDirection.Out,
     math.Huge -- This Loops it over and over
     false,
     0
)

local Goal = {
     CFrame = Part.CFrame * CFrame.Angles(0, math.rad(90), 0)
}

local Tween = TweenService:Create(Part, Info, Goal)
Tween:Play()

Sorry if there are errors in this code.

9 Likes

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