Setting CFrame of Part while Spinning it

I don’t know if Gyazo is catching this but basically this is what it is doing:
https://gyazo.com/1dca69c1e1bf6ca516469898d3265ae2

well you could try doing something like Part.Orientation = HumanoidRootPart.Orientation + Vector3.new(x, y, z) I’ll test this then edit this message if it works or not. Well the one time I tried, it didnt work, but you could definitely try doing something like that with tweening, unless you want constant spin, then you could try using constraints or align orientation, I’d recommend constraints.

I’d really not want to try using Orientation or Position as I heard constantly setting that on loop is bad compared to CFrame though I may be wrong :man_shrugging:

i know, thats why i said set the * CFrame.Angles() when defining the orientation. If you dont want it to spin do it like this:

local Offset = Root.CFrame * CFrame.new(0, 0, -2) * CFrame.Angles(math.rad(180), 0 0)
Part.CFrame = Part.CFrame:Lerp(Offset, 0.8)

I might be sending the message across wrong but, I still want to keep it spinning however, I don’t want it to spin at uncontrollable speeds while inside the Stepped loop.

Then just have a value that you set the cframe.angles to. And take that value +1 or something ever loop.

It is not the best way but it works, the best way would just be to use what i said first. But dont set the value that high.

As I’ve said in the reply before, it leads to uncontrollable speeds since it is inside the loop. Setting it in a while true do loop with a wait() also doesn’t help. And I’m setting the value at 0.001 which changes nothing in its speed.

EDIT: Please read my post again, I’ve made the value 0.001, and yet it is still spinning like crazy.

just make it really low then, like 0.1 or even 0.05. It is still going the same speed, it is just to fast.

i have it to 1 and it works perfectly fine https://gyazo.com/f8ddb39fa2dd2e40e72bfe3b627a4adb

If possible, can you show me how you’re doing it? I’m setting it to the lowest I can while it still does this:
https://gyazo.com/9fb9b265a5a3497ccecd1316a615a2d2

Why not make use of bodyforces to allow the part to spin and follow the character as well? You can update the Cframe through this as well.

here is the entire code i use: lua local Part = Instance.new("Part", character) Part.Anchored = true local Root = character:WaitForChild("HumanoidRootPart") local n = 0 while true do local Offset = Root.CFrame * CFrame.new(0, 0, -2) * CFrame.Angles(math.rad(n), 0, 0) Part.CFrame = Part.CFrame:Lerp(Offset, 0.8) n = n+1 if n == 360 then n = 0 end game:GetService("RunService").Heartbeat:Wait() end

https://gyazo.com/0af4cd58eb68e554ded9c60a6e345508

i for some reason cant make it a code block, idk why.

Looking at the code, it seems as though you’re constantly adding a value of + 1 to the variable, wouldn’t that be bad as it keeps going bigger and bigger as time goes by to like 95028520528015?

@Painshinratensei, I’d rather not rely on physics and bodygyros/etc for this as I plan to use CFrames and some sine waves/etc

oh, i forgot that, just make it so everytime it reaches 360 set it to 0 again

It might just be me but doesn’t this seem hacky? In this post, I’m reading, it shows that it is just being multiplied to spin without having to rely on a seperate variable constantly updating alongside and setting it back? (tried it already though but didn’t work, might be because I’m doing something wrong :man_shrugging:)

I think you are thinking of when setting the old cframe of the part *cframe.angles(math.rad(n), 0, 0) that would not be good. But since you are making a new cframe it should not matter.

And no, for me it is perfectly smooth

I got it working with for i = 0, 359, 3 do loop

I meant as in:

while true do
wait()
local NumValue = 0
NumValue = NumValue + 1
-- Using NumValue for it
-- Setting it back to 0
-- Is constantly being done, reconnected and disconnected
end

Isn’t that somewhat hacky to store a variable for that or somewhat can be bad for performance?

@coworkerplus, I’m pretty sure that will just do it once unless it is done in a loop :thinking:

yeah i put it in a while true do loop so there is no wait time when the for loop ends

Set local NumValue = 0 outside the loop and from what i know that should work perfectly fine, if you just remember to set it to 0 when it reaches 360.

1 Like

pretty sure that just made it 100 times more complicated than it had to be, wouldn’t that loop the for loop which leads to looping the loop aka:

Loops within Loops.

@index_nil, I’ll use your method than, thank you :+1:

However, if anybody has a better way of updating the value, please reply, but I’ll mark @index_nil as solution since he helped, thank you :+1:

1 Like