How do I make a model face the player?

I made a pet model that will follow the player as a test. It uses this code right here:

local function SetPetCFrame()
	
	local pos = Vector3.new(Hroot.Position.X + 2, Hroot.Position.Y + 3,Hroot.Position.Z + 2)
	
	Pet:SetPrimaryPartCFrame(CFrame.new(pos,Hroot.Position))

end 

game:GetService("RunService").RenderStepped:Connect(SetPetCFrame)

The pet does follow the player, but it doesn’t really turn to the player.
It’s primarypart is called “Handle” and it’s FrontSurface is the same angle as the head.

1 Like

It looks like it should work, because the LookAt parameter of the CFrame is correct. This may not be a fix, but it may look nicer if you set the CFrame before applying it as a parameter to the SetPrimaryPartCFrame. So inside the function:

local characterPosition = Hroot.Position
local teleportPosition = characterPosition + Vector3.new(2,3,2)

local cframe = CFrame.new(teleportPosition, characterPosition)
Pet:SetPrimaryPartCFrame(cframe)

This may not do anything, but now you can output characterPosition and teleportPosition to see if they actually exist.

I’d also suggest making game:GetService(‘RunService’) a variable. I think it has very little impact on performance but I think it’s bad practice, as it’s running every render.

I hope this helps a bit. What do the output variables print?

1 Like

You can just set the pets’ CFrame to the humanoidrootpart’s CFrame, then you can use vector3’s to position it beside the humanoidrootpart:

pet:SetPrimaryPartCFrame(Hroot.CFrame + Vector3.new(2, 3, 2))
1 Like

The output prints the root part’s position, but the dragon stays in one rotation.

[ a picture would be here but devforum isnt letting me upload photos ]

1 Like

Okay, let me try that…

|| 30 chars ||