How can I change a cframe's orientation without changing its position?

I want to rotate the wheels of a bike with CFrame.Angles. However, when I try to do this at faster speeds the wheels start moving position aswell. I’m rotating using the model’s pivot which might be the issue.

while true do 
workspace.SingleWheel:PivotTo(workspace.SingleWheel:GetPivot() * CFrame.Angles(0,0,math.deg(.001))) 
task.wait() 
end
1 Like

Your issue is that PivotTo moves the entire model’s pivot. Each multiplication with CFrame.Angles is applied in world space, and small floating-point errors accumulate. That’s why the wheel drifts instead of only spinning.

This may work..

local front = workspace.Bike.FrontWheel
local back = workspace.Bike.BackWheel
local baseFront = front:GetPivot()
local baseBack = back:GetPivot()
local a = 0

while true do
    a += 0.1
    front:PivotTo(baseFront * CFrame.Angles(0,0,a))
    back:PivotTo(baseBack * CFrame.Angles(0,0,a))
    task.wait()
end

Not sure how you’re moving the bike so..

local bike = workspace.Bike
local front = bike.FrontWheel
local back = bike.BackWheel

local baseFront = front:GetPivot()
local baseBack = back:GetPivot()
local aFront, aBack = 0, 0

local radius = 2 -- set this to match the actual wheel radius

while true do
    local vel = bike.PrimaryPart.AssemblyLinearVelocity.Magnitude
    local rot = vel / radius
    aFront += rot
    aBack += rot
    front:PivotTo(baseFront * CFrame.Angles(0,0,aFront))
    back:PivotTo(baseBack * CFrame.Angles(0,0,aBack))
    task.wait()
end

Problem is I can only use the model. I could weld all of it but theres 30+ meshparts so idk how to get the front part really.

In Studio, group all the parts of the front wheel into a FrontWheel model, do the same for the back. Then you can rotate them separately as shown.

2 Likes

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