My skinned mesh npcs orientation keeps messing up and flinging him

Since I have to manually orientate my skinned mesh I use look at to make it face the target its walking towards although it has collision issues. I’m not sure how I could implement a fix so any help is appreciated.

local hound = script.Parent
local humanoid = hound:FindFirstChild("Humanoid")
local houndRootPart = hound.PrimaryPart

local pathFindingService = game:GetService("PathfindingService")
local waypointFolder = workspace.Waypoints

local function getPath(destination)
	local pathParams = {
		["AgentHeight"] = 5,
		["AgentRadius"] = 30,
		["AgentCanJump"] = false,
	}
	local path = pathFindingService:CreatePath(pathParams)
	path:ComputeAsync(houndRootPart.Position, destination.Position)
	
	return path
end

local function walkTo(destination)
	local path = getPath(destination)
	
	for i, subWayPoint in pairs(path:GetWaypoints()) do
		houndRootPart.CFrame = CFrame.lookAt(houndRootPart.Position, subWayPoint.Position)
		
		humanoid:MoveTo(subWayPoint.Position)
		humanoid.MoveToFinished:Wait()
	end
end

local function wandering()
	for i, waypoints in pairs(waypointFolder:GetChildren()) do
		walkTo(waypoints)
	end
	return
end

while task.wait(2) do
	wandering()
end
3 Likes

I know there are probably other ways of fixing this, but have you tried rotating your Mesh 90° to the left in your 3D program and saving it, then loading that file into your MeshPart?

2 Likes

sorry but how would that help the rotation is fine its just the fact it sometimes changes the y rotation?

3 Likes

I thought Humanoid:MoveTo() always faced the direction the Humanoid was walking to anyway? If you update the position before the 8 second maximum time allowed for a MoveTo to finish then the NPC should always face toward you. Check the script(s) in the link I posted.

2 Likes

yeah i had a problem with that recently, i just decided on using cframe.lookat
check this post as i explained it better in their

1 Like