Getting an npc underwater to face the direction its moving towards


The fish is doing a weird flip every time it moves.

local Humanoid = script.Parent.Humanoid
local HumanoidRootPart = script.Parent.HumanoidRootPart

while true do
	local pos = HumanoidRootPart.Position
	local TargetPos = Vector3.new((pos.X + math.random(-30, 30)), pos.Y, (pos.Z + math.random(-30, 30)))

	local direction = (TargetPos - pos).unit

	HumanoidRootPart.CFrame = CFrame.lookAt(pos, TargetPos)
	wait()
	Humanoid:MoveTo(TargetPos)
	Humanoid.MoveToFinished:Wait()
end

This is what I use to move the fish
image
This is how the fish is structured

What can I do to fix this flippy move?

1 Like

Flip is because of AlignOrientation, change AlignOrientation to oneattachment, and set Cframe to align orientation instead of changing rootpart cframe.

Where should this attachment be? I tried butting it in the union and the HumanoidRootPart, but both of them sent the fish out of existence