I’m trying to do a simple follow script where an NPC (a cat in this case) follows me. I’ve created the cat as an R15 humanoid and given it a very basic model just for testing purposes. My follow script looks like this:
Owner = This.Owner.Value
while true do
wait(math.random(2, 6))
if State == StateFollowing then
TargetPos = Owner.Character.HumanoidRootPart.Position
local CurrentPos = This.HumanoidRootPart.Position
Humanoid:MoveTo(TargetPos, Owner.Character.HumanoidRootPart)
end
end
But the NPC isn’t facing me, instead he just walks sideways to get to me and is off by 90 degrees.
Here’s a screenshot of my HumanoidRootPart properties for the NPC:
Hey, yeah you will have to use CFarme.Angels to make this work, here is an example you can play with:
This is example for a part not a model. You will have to play around with X,Y and Z axis oriantation to get the best fit for your model or part.
Here is an example in model in which you will have to change PrimaryPart oriantation if you don’t have selected primary part on the model then make sure you do it:
local ModelCFrame = game:GetService("Workspace"):FindFirstChild("NameOfModel").PrimaryPart.CFrame
Model:SetPrimaryPartCFrame(ModelCFrame * CFrame.Angles(math.rad(x),math.rad(y),math.rad(z))
Here is an example how it should look like in your code:
Owner = This.Owner.Value
while true do
wait(math.random(2, 6))
local ModelCFrame = game:GetService("Workspace"):FindFirstChild("NameOfModel").PrimaryPart.CFrame
if State == StateFollowing then
Model:SetPrimaryPartCFrame(ModelCFrame * CFrame.Angles(math.rad(x),math.rad(y),math.rad(z))
TargetPos = Owner.Character.HumanoidRootPart.Position
local CurrentPos = This.HumanoidRootPart.Position
Humanoid:MoveTo(TargetPos, Owner.Character.HumanoidRootPart)
end
end
Neither of the above suggestions works because AFAICT Humanoid:MoveTo overwrites the model’s CFrame in order to make its orientation the same as the model’s. So whatever the model’s CFrame is before I call Humanoid:MoveTo is going to be completely lost after I call it. I’ve tried setting the model’s orientation to tons of different values before before I clone it into the workspace, as well as right before I call MoveTo, and the results are always exactly the same.
This is due to the root part of your cat having an incorrect orientation. Your HumanoidRootPart’s Front face should be the same face as where the cat’s head is. You can see where the front face is by selecting the root part and clicking on the front face surface type in the properties window (which will highlight the front face).
In order to fix your issue, first delete any joints directly connecting the root part to the cat model. After that reorient your HumanoidRootPart so it has the same orientation as the cat model and then create new joints.
Additionally, you may want to make sure the limbs of your cat are facing the correct way otherwise you may run into animation issues.
Additionally, Humanoids base their movement/physics entirely on
The humanoid root part and its orientation (determines how the humanoid rotates when moving, e.g. the front face of the part will face the direction of movement)
The HipHeight of the humanoid (determines how high from the Bottom face of the humanoid the root part should sit)
The mass of connected parts and the center of mass of the humanoid