I’m trying to make a unit movement with unanchored models, and it seems that I face some issues when I attempt to make the models face in a certain direction (i.e enemy object). What I want is so that the units’s direction of movement stays constant to their destination while they are moving, but the unit would rotate facing another object if necessary. I did a test code:
local primaryPart = model.PrimaryPart
local currentPos = primaryPart.Position -- Vector3
-- Determine where to look (nearby block or current facing direction)
local lookAtPosition = nil
lookAtPosition = destination[1]
-- Calculate movement direction towards destination
local direction = (destination[1] - currentPos).Unit
local distance = (destination[1] - currentPos).Magnitude
local moveStep = direction * MOVE_SPEED * deltaTime
-- Move the primary part
local newPos = currentPos + moveStep
local lookAt = CFrame.lookAt(newPos, workspace.Origin.Position) -- main issue
model:SetPrimaryPartCFrame(lookAt)
Result:
But if the code is replaced with:
local lookAt = CFrame.lookAt(newPos, newPos + direction)
No issues in the unit’s trajectory are observed, though it does not meet my needs.
I tried using AlignOrientation with PrimaryAxisLookAt, however, it recreates the same pathway issue.