I’m trying to learn inverse kinematics but I don’t understand why he scripted the CharacterIK in this way.
Local script in StarterPlayerScripts:
local RunService = game:GetService("RunService")
local parts = {}
local function CharacterAdded(character)
task.wait()
local ik = Instance.new("IKControl")
ik.Type = Enum.IKControlType.LookAt
ik.ChainRoot = character.UpperTorso
ik.EndEffector = character.Head
ik.Target = parts[game.Players:GetPlayerFromCharacter(character)]
ik.Weight = 0.555
ik.Parent = character.Humanoid
character.Humanoid.Died:Wait() ik:Destroy()
end
local function PlayerAdded(player)
local part = Instance.new("Part")
part.CanCollide = false
part.CanQuery = false
part.CanTouch = false
part.Transparency = 1
part.Anchored = true
part.Parent = workspace
parts[player] = part
if player.Character ~= nil then CharacterAdded(player.Character) end
player.CharacterAdded:Connect(CharacterAdded)
end
local function PlayerRemoving(player)
parts[player]:Destroy()
parts[player] = nil
end
for i, player in game.Players:GetPlayers() do PlayerAdded(player) end
game.Players.PlayerAdded:Connect(PlayerAdded)
game.Players.PlayerRemoving:Connect(PlayerRemoving)
RunService.RenderStepped:Connect(function(deltaTime)
for player,part in parts do
if player.Character == nil then continue end
part.Position = player.Character.Head.Position + player:GetAttribute("LookVector") * 10
end
end)
I don’t understand why he uses indexes of players in his parts table in a local script and why PlayerAdded/CharacterAdded events are being used on the client.