Making a pet look in the direction of the player

My problem is that my pet doesn’t forward in the direction of its owner

I’ve searched and experimented for a few hours, using CFrame to make it LookAt wherever the player looks at “works” but it causes my pet to glitch and stutter because of the loop in my code

Align Orientation was working fine, but when I switched pets it does not face forward and look where my character looks (It’s like my pets forward is not the characters forward so it is Aligning but not Aligning in the way I want it to)

Code(All Local for Testing)

local RunService = game:GetService('RunService')

local Player = game.Players.LocalPlayer
local Character = Player.Character
local Humanoid = Character.Humanoid
local Root = Character.HumanoidRootPart

local Pet = game.ReplicatedStorage.Part:Clone()



function SpawnPet()
	local BodyPosition = Instance.new("BodyPosition")
	BodyPosition.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
	BodyPosition.P = 15000
	BodyPosition.Parent = Pet
	

	Pet.Parent = workspace
	
	local function Pet_Follow()
		
		BodyPosition.Position = (Root.CFrame * CFrame.new(5, 3, 5)).p
		
	end
	
	RunService.Heartbeat:connect(Pet_Follow)
	
end

SpawnPet()

I’m going to make a pet system once I figure out this Orientation problem and post it somewhere in the dev forums due to people wanting a pet system that’s actually smooth and doesn’t lag/stutter

If anyone has a solution, or a way to make the Align Orientation work properly post below

Thanks, Quoteory

6 Likes

Have you tried using :MoveTo and :SetPrimaryPartCFrame

1 Like

Those methods are both choppy and not smooth, the movement is already done I just need to make it face in a direction properly

2 Likes

I figured it out

I added this code

Pet.Orientation = Root.Orientation + Vector3.new(0, 90, 0)

to make the Orientation match up

6 Likes

You could also add a BodyGyro and set the CFrame to your HumanoidRootPart’s CFrame.

1 Like

How exactly would you do that in this case, I added a BodyGyro and set its CFrame to my RootPart’s CFrame and parented it to the pet and it did nothing, am I not doing it properly?

1 Like

Parent the BodyGyro to the PrimaryPart, with math.huge in xyz in the MaxTorque

and loop this following line



bg.CFrame = player.Character.HumanoidRootPart.CFrame + player.Character.HumanoidRootPart.CFrame.lookVector *1


bg is your BodyGyro

1 Like

there is still an Orientation problem using that

image

1 Like

Make sure to have the PrimaryPart face the direction of the face of your pet.

I assume that your PrimaryPart is facing left of your pet’s face

Basically front surface must be where the face is looking at

1 Like

I was just using a union the whole time, having a primarypart would make this so simple and I didn’t even consider it

Thanks

2 Likes

Also xPolo is there any particular benefit to using Gyro over Orientation performance/vanity wise because Orientation is a lot less code

1 Like

You can manipulate BodyGyro to make your pet turn smoothly, with the following properties:

bg.D : Determines the amount of dampening to use in reaching the goal CFrame
bg.P : Determines how aggressive of a torque is applied in reaching the goal orientation

I believe in the screenshot you provided, you can see how fast your pet changes its face direction.

2 Likes

Yes, I have just tested it and it rotates smoothly, and Orientation was not working with a PrimaryPart either Gyro is great

2 Likes

You can use AlignOrientation:

  1. Create an attachment on the pet
  2. Create an AlignOrientation constraint on the pet
  3. Set the Attachment0 to the attachment created on 1
  4. With a script, set the Attachment1 to one of the player’s characters attachments, for example RootRigAttachment:
AlignOrientation.Attachment1 = Root:FindFirstChild("RootRigAttachment")
2 Likes

I believe Gyro would be the better option in my case, but it’s still great to see more solutions as others can learn

1 Like
1 Like

Oh, I see so AlignOrientation is a upgraded version of Gyro?

I’ll have to experiment

1 Like