Hello! Im working on my pets system, and im struggling with positioning the pets infront of my camera (For the first time i tried to use ViewportFrames, but now i want to use only CFrame, because ViewportFrames do not display Highlights and Particle Effects)
-
What do you want to achieve?
I want to set pets position infront of camera, and also change their orientation to face the camera. -
What is the issue?
When im moving my camera up/down pets starts rotating weirdly, Im not good at CFrames so its hard for me.
-
What solutions have you tried so far?
Tried to set Z axis in CFrame.lookAt() to Pet.Position instead of Camera.Position, so it wont rotate by Z axis, but it brokes everything. Also tried to look at other topics and tried their solutions but nothing works as it must.
Code:
local Positions = {
[1] = {X = -0.9, Y = 0},
[2] = {X = 0, Y = 0},
[3] = {X = 0.9, Y= 0}
}
function CameraAttach(Pet, XPos, YPos)
rsConnection[Pet] = rs.RenderStepped:Connect(function()
Pet.CFrame = Camera.CFrame * CFrame.new(XPos, YPos, -1)
Pet.CFrame = CFrame.lookAt(Pet.Position, Vector3.new(Camera.CFrame.Position.X, Camera.CFrame.Position.Y, Camera.CFrame.Position.Z))
end)
end