How to Rotate Pet Upright

I have a pet following script which works fine except for the fact that the pet looks like it’s laying on its back. This is because the front surface is faced upward. What is the best way to rotate the pet vertically within the script and maintain its ability to orient itself horizontally?

--Follow Script
function follow()
	local HRootPart = script.Parent.Parent:WaitForChild("HumanoidRootPart")
	local BodyPosition = script.Parent:WaitForChild("BodyPosition")
	local BodyGyro = script.Parent:WaitForChild("BodyGyro")
	BodyPosition.Position = HRootPart.Position + HRootPart.CFrame.lookVector*-4 + HRootPart.CFrame.upVector*-2 + HRootPart.CFrame.rightVector*3
	BodyGyro.CFrame = HRootPart.CFrame * CFrame.new(3,0,-3)
end

game:GetService("RunService").Heartbeat:Connect(follow)

Edit: The pet is a MeshPart if that changes anything

You can fix this simply by rotating your CFrame:

BodyGyro.CFrame = (HRootPart.CFrame * CFrame.Angles(0, math.rad(90), 0)) * CFrame.new(3,0,-3)

Not exactly sure which axis is the key, but I assume you only need 90 degrees of rotation on one of them. Either way, this logic should do the trick.

1 Like

That works perfectly! Thank you

1 Like