Very basic CFrame not working?

You can open up a new baseplate and test this small code snippet:

local part = workspace.Part
part.TopSurface = Enum.SurfaceType.Motor
part.FrontSurface = Enum.SurfaceType.Hinge
part.BrickColor = BrickColor.new("Really blue")

local startCF = CFrame.new(Vector3.new(32.5, 1.5, -0.5))
local rs = game:GetService("RunService")

for i = 1,100 do
	local lookAtCF = CFrame.new(startCF.Position,((startCF * CFrame.new(Vector3.new(0,0,-1))).Position) + Vector3.new(0,-i/100,0))
	part.CFrame = lookAtCF
	rs.RenderStepped:Wait()
end


It works like it’s supposed to, then test the Z Rotation:

local part = workspace.Part
part.TopSurface = Enum.SurfaceType.Motor
part.FrontSurface = Enum.SurfaceType.Hinge
part.BrickColor = BrickColor.new("Really blue")

local startCF = CFrame.new(Vector3.new(32.5, 1.5, -0.5))
local rs = game:GetService("RunService")

for i = 1,100 do
part.CFrame *= CFrame.Angles(0,0,math.rad(-3))
rs.RenderStepped:Wait()
end

also works like its supposed to, but then something weird happens when you combine them:

local part = workspace.Part
part.TopSurface = Enum.SurfaceType.Motor
part.FrontSurface = Enum.SurfaceType.Hinge
part.BrickColor = BrickColor.new("Really blue")

local startCF = CFrame.new(Vector3.new(32.5, 1.5, -0.5))
local rs = game:GetService("RunService")

for i = 1,100 do
	local lookAtCF = CFrame.new(startCF.Position,((startCF * CFrame.new(Vector3.new(0,0,-1))).Position) + Vector3.new(0,-i/100,0))
	part.CFrame = lookAtCF * CFrame.Angles(0,0,math.rad(-3))
	rs.RenderStepped:Wait()
end

I want to get it to tilt forward while rotating on its Z axis.
I don’t understand why this is functioning like this, could someone explain?

1 Like

see how it’s kinda tilting on the Z but not really, that’s very weird. I tried running through my head the order of events but still confused… my logic is all jacked up Lol

Shouldn’t it tilt the front down and rotate the Z at the same time?

why not just take currentCf*CFrame.Angles(math.rad(3),0,math.rad(-3))

1 Like

I’ll try that, hang on one sec

Thing is this operation remembers the current state of the part after being rotated as part.CFrame

However this state gets overwritten to lookAtCf hence it first goes to the lookAtCF then tilts only -3 degrees on the axis, then goes to the next lookat CFrame resetting the Z axis rotation then only tilts a lil by -3 degrees.

I would do try this out:

part.CFrame = lookAtCF * CFrame.Angles(0,0,math.rad(-3*(i-1)))

2 Likes

Also you’re not rotating relative to the lookAtCF.
lookAtCF* (lookAtCF:ToWorldSpace(CFrame.Angles(0,0,math.rad(-3))))

That doesn’t work, makes it rotate 360 on both axis which isn’t what I want

This worked! Thanks man, i’ll be sure to remember that

1 Like

This didn’t work either, but thanks for your help