I'm currently developing a game that includes animals. The animals are supposed to wander around and when I was making a script to do so, I stumbled across the problem of the animal not facing the way I want it to face when I make it move around. Here's my script (for your reference)
local humanoid = script.Parent:WaitForChild('Humanoid') local pp1 = script.Parent.Parent:WaitForChild('PathingPart1') local pp2 = script.Parent.Parent:WaitForChild('PathingPart2') local pp3 = script.Parent.Parent:WaitForChild('PathingPart3') script.Parent.PrimaryPart = script.Parent:WaitForChild('Head') --- while humanoid.Health > 0 do wait(5) script.Parent:SetPrimaryPartCFrame(???) -- Supposed to make the model rotate towards the part it's moving to humanoid:MoveTo(pp1.Position) -- Moves the model wait(5) script.Parent:SetPrimaryPartCFrame(???) -- Same goes for here humanoid:MoveTo(pp2.Position) -- Moves the model wait(5) script.Parent:SetPrimaryPartCFrame(???) -- And here aswell humanoid:MoveTo(pp3.Position) -- Moves the model end
Thank you for taking some to read/answer/comment on this question
To look at a position, you put that position as the second argument (rotation) of the CFrame. I am not sure why it works but it does. If you want to base it off of the velocity... velocity is a vector that is an offset from (0,0,0), so if you tried to use it you would always face near the origin. You can instead offset from your position by adding the two.
part.CFrame = CFrame.new(part.Position,part.Position+part.Velocity
This faces toward where you are moving :)