Hello, I have been working on a pet follower script but I am trying to make the pets face forward instead of facing the HumanoidRotPart.
What do you want to achieve?
I want the pets to face forwards like this:
wait(5)
local runService = game:GetService("RunService")
local character = script.Parent
local hrp = character:WaitForChild("HumanoidRootPart")
local wands = workspace.PlayerWands:FindFirstChild(character.Name)
local numberOfWands = 4
local fullCircle = 2 * math.pi
local radius = 7
local function getXAndZPositions(angle)
local x = math.cos(angle) * radius
local z = math.sin(angle) * radius
return x, z
end
runService.RenderStepped:Connect(function()
for i, part in pairs(wands:GetChildren()) do
local angle = i * (fullCircle / #wands:GetChildren())
local x, z = getXAndZPositions(angle)
local position = (hrp.CFrame * CFrame.new(x, 0, z)).p
local lookAt = hrp.CFrame.LookVector
part:SetPrimaryPartCFrame(CFrame.new(position, lookAt))
end
end)
Here is my current script that makes the pets face the HumanoidRootPart:
wait(5)
local runService = game:GetService("RunService")
local character = script.Parent
local hrp = character:WaitForChild("HumanoidRootPart")
local wands = workspace.PlayerWands:FindFirstChild(character.Name)
local numberOfWands = 4
local fullCircle = 2 * math.pi
local radius = 7
local function getXAndZPositions(angle)
local x = math.cos(angle) * radius
local z = math.sin(angle) * radius
return x, z
end
runService.RenderStepped:Connect(function()
for i, part in pairs(wands:GetChildren()) do
local angle = i * (fullCircle / #wands:GetChildren())
local x, z = getXAndZPositions(angle)
local position = (hrp.CFrame * CFrame.new(x, 0, z)).p
local lookAt = hrp.Position
part:SetPrimaryPartCFrame(CFrame.new(position, lookAt))
end
end)
Try printing the LookVector of the HumanoidRootPart.
Edit:
you want to do this:
wait(5)
local runService = game:GetService("RunService")
local character = script.Parent
local hrp = character:WaitForChild("HumanoidRootPart")
local wands = workspace.PlayerWands:FindFirstChild(character.Name)
local numberOfWands = 4
local fullCircle = 2 * math.pi
local radius = 7
local function getXAndZPositions(angle)
local x = math.cos(angle) * radius
local z = math.sin(angle) * radius
return x, z
end
runService.RenderStepped:Connect(function()
for i, part in pairs(wands:GetChildren()) do
local angle = i * (fullCircle / #wands:GetChildren())
local x, z = getXAndZPositions(angle)
local position = (hrp.CFrame * CFrame.new(x, 0, z)).p
local lookAt = -hrp.CFrame.LookVector --BackVector
part:SetPrimaryPartCFrame(CFrame.new(position, lookAt))
end
end)
wait(5)
local runService = game:GetService("RunService")
local character = script.Parent
local hrp = character:WaitForChild("HumanoidRootPart")
local wands = workspace.PlayerWands:FindFirstChild(character.Name)
local numberOfWands = 4
local fullCircle = 2 * math.pi
local radius = 7
local function getXAndZPositions(angle)
local x = math.cos(angle) * radius
local z = math.sin(angle) * radius
return x, z
end
runService.RenderStepped:Connect(function()
for i, part in pairs(wands:GetChildren()) do
local angle = i * (fullCircle / #wands:GetChildren())
local x, z = getXAndZPositions(angle)
local position = (hrp.CFrame * CFrame.new(x, 0, z)).p
local lookAt = hrp.Position
part:SetPrimaryPartCFrame(CFrame.new(position, lookAt) * CFrame.Angles(0,math.rad(-90),0))
end
end)