Here’s my code:
local function UpdateCam(enemy)
local hrpPos, dummyPos = char.HumanoidRootPart.Position, enemy.Torso.Position
local CFam = CFrame.new(hrpPos, Vector3.new(dummyPos.X, hrpPos.Y, dummyPos.Z))
local CamCFam = CFrame.new(hrpPos+Vector3.new(0,2,0), Vector3.new(dummyPos.X, hrpPos.Y, dummyPos.Z))*CFrame.new(3, 1, 8)
workspace.CurrentCamera.CFrame = CamCFam
char.HumanoidRootPart.CFrame = CFrame.lookAt(hrpPos, Vector3.new(dummyPos.X, char.HumanoidRootPart.Position.Y, dummyPos.Z))
end
RS.Heartbeat:Connect(function()
local winner = nil
local objTable = {}
for i, otherplr in pairs(game.Players:GetPlayers()) do
if otherplr ~= plr and otherplr.TeamVal ~= plr.TeamVal then
table.insert(objTable, otherplr.Character)
end
end
for i, npc in pairs(workspace:WaitForChild("HostileNPCs"):GetChildren()) do
table.insert(objTable, npc)
winner = npc
end
for i, person in pairs(objTable) do
if (person.Torso.Position - char.Torso.Position).Magnitude < (winner.Torso.Position - char.Torso.Position).Magnitude then
winner = person
end
end
if (winner.Torso.Position - char.Torso.Position).Magnitude <= 30 then
cam.CameraType = Enum.CameraType.Scriptable
UpdateCam(winner)
else
cam.CameraType = Enum.CameraType.Custom
end
end)
Here’s the visual:
IMPORTANT: I noticed it works fine with the person who’s idle:
try using RenderStepped rather than Heartbeat
local function UpdateCam(enemy)
local hrpPos, dummyPos = char.HumanoidRootPart.Position, enemy.Torso.Position
local CFam = CFrame.new(hrpPos, Vector3.new(dummyPos.X, hrpPos.Y, dummyPos.Z))
local CamCFam = CFrame.new(hrpPos+Vector3.new(0,2,0), Vector3.new(dummyPos.X, hrpPos.Y, dummyPos.Z))*CFrame.new(3, 1, 8)
workspace.CurrentCamera.CFrame = CamCFam
char.HumanoidRootPart.CFrame = CFrame.lookAt(hrpPos, Vector3.new(dummyPos.X, char.HumanoidRootPart.Position.Y, dummyPos.Z))
end
RS.RenderStepped:Connect(function()
local winner = nil
local objTable = {}
for i, otherplr in pairs(game.Players:GetPlayers()) do
if otherplr ~= plr and otherplr.TeamVal ~= plr.TeamVal then
table.insert(objTable, otherplr.Character)
end
end
for i, npc in pairs(workspace:WaitForChild("HostileNPCs"):GetChildren()) do
table.insert(objTable, npc)
winner = npc
end
for i, person in pairs(objTable) do
if (person.Torso.Position - char.Torso.Position).Magnitude < (winner.Torso.Position - char.Torso.Position).Magnitude then
winner = person
end
end
if (winner.Torso.Position - char.Torso.Position).Magnitude <= 30 then
cam.CameraType = Enum.CameraType.Scriptable
UpdateCam(winner)
else
cam.CameraType = Enum.CameraType.Custom
end
end)
2 Likes
Nope. didn’t fix I just tested.
if its then use BindToRenderStep
Look at the idle person, they work fine:
Bumping. Hope someone will help.
I fixed it by using a bodygyro! Estoy mucho contento
1 Like