Setting CFrame of Part while Spinning it

If it’s still confusing, I’ll give some context:

https://gyazo.com/ef8d2ff140f51969e27069e350e69362

Essentially, I’m setting the part infront of the player’s rootpart, if they move, it’s still infront of them as usual, they turn, still infront of them.

However, the Issue I’m having is wanting to rotate the part based on it’s current rotation while still allowing it to follow/CFrame infront of the player’s root as usual.

RunService.Stepped:Connect(function()
     local Offset = Root.CFrame * CFrame.new(0, 0, -2)
     Part.CFrame = Part.CFrame:Lerp(Offset, 0.8)
end)

Here is my current code, basically, a normal setting it infront of the player dealio contained inside a loop. How would I go about doing this and rotating the part?

2 Likes

how fast do you need it to update? is the lerping necessary?

I’m lerping it to smoothly move the part infront of the player, just ignore it as of now.

I just need to make it rotate somewhat quickly but not too quick however, I still want to try and see how I would do this myself. Basically, I just want to try and rotate the part infront of the player dependent on it’s rotation constantly while setting it infront of the player constantly at the same time.

just put a * CFrame.Angles() after lerping

2 Likes

a way I would to it is to have it update every frame to put it in front of the character then have the part’s orientation the same as the humanoidrootpart or torso

I probably should’ve added the Stepped before hand but now I did :sweat_smile:

Anyways, doing that does somewhat work however, it just leads to insane spinning speeds.

@coworkerplus, I want to have it spin instead of just setting it infront of the player. The positioning infront of the player is ok, that works perfectly fine, the spinning part is not working out so well.

Oh, set the CFrame.Angles() when defining the offset, then it will have that orientation

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