Issue with CFrames

I have a model that I need to move between two parts and face where it’s moving. It moves between the parts just fine, but I can’t figure out how to make it face the right way.

Relevant portion of the script.

local StartPoint = workspace.Start
local MoveToPoint = workspace.End

for _, Waypoint in pairs(waypoints) do
	local CFrameValue = Instance.new("CFrameValue")
	CFrameValue.Value = Model:GetPrimaryPartCFrame()
	CFrameValue:GetPropertyChangedSignal("Value"):Connect(function()
		Model:SetPrimaryPartCFrame(CFrameValue.Value)
	end)

	local ToMove = CFrame.new(Waypoint.Position + Vector3.new(0,Height,0)) * CFrame.Angles(End.Position.X,End.Position.Y,End.Position.Z)
		
	local Tween = TweenService:Create(CFrameValue, TweenInfo.new(Time, Enum.EasingStyle.Linear), {Value = ToMove})
	Tween:Play()
	Tween.Completed:Wait()
	CFrameValue:Destroy()
end

When I do local ToMove = CFrame.new(Waypoint.Position + Vector3.new(0,Height,0)) * CFrame.Angles(End.Position.X,End.Position.Y,End.Position.Z) it faces somewhere, but now where it needs to face.

Everything else I’ve tried either made it spin randomly, or not do anything at all. How would I make it face where it needs to move?

Try this:

    local rot = CFrame.lookAt(Vector3.new(), End.Position)
	local ToMove = CFrame.new(Waypoint.Position + Vector3.new(0,Height,0)) * CFrame.Angles(rot:ToEulerAnglesYXZ())

That kinda worked. It now spins the right way now, but not enough.

Video.

Oh sorry I misunderstood your problem, here it the solution:

    local directionToGetThere = (End.Position - Waypoint.Position).Unit
	local destinationCFrame  = CFrame.lookAt(End.Position, End.Position + directionToGetThere)

Had to make a slight change, but it worked! Thank you!

1 Like