im trying to make a character look at my character. every time i jump when im within distance of the other character, the character comes straight to me and shoots like 50 feet into the air lol. what could be the problem? i tried a few solutions via devforum but i havent gotten it to work yet. i appreciate any help ty!!
game.Players.PlayerAdded:Connect(function(p)
p.CharacterAdded:Connect(function(c)
local DISTANCE = 15
local plrHum:Humanoid = c:FindFirstChildOfClass("Humanoid")
local hrp = c:WaitForChild("HumanoidRootPart")
local function update()
local mag = (hrp.Position - catHRP.Position).Magnitude
if mag < DISTANCE then
cat.Head.CFrame = CFrame.lookAt(cat.Head.Position, c.Head.Position)
if not playing then
runAnimTrack:Play()
playing = true
end
else
runAnimTrack:Stop()
playing = false
end
end
connection = rs.Stepped:Connect(update)
plrHum.Died:Connect(function()
connection:Disconnect()
end)
end)
end)
hey king!!!
i would if i didnt need to move it but im planning to make the dummy walk backwards away from me if i walk close to it. the problem is with the lookat. its really weird tho. ty 4 the help as always btw !
local cat = workspace:FindFirstChild("catr6")
local jerry = workspace:FindFirstChild("jerryrigorsum")
local catHRP = cat.HumanoidRootPart
local cat_humanoid:Humanoid = cat:FindFirstChildOfClass("Humanoid")
local cat_animator:Animator = cat_humanoid.Animator
local rs = game:GetService("RunService")
local runanim = cat.run
local alignOrientation = cat.AlignOrientation
local alignPos = cat.AlignPosition
local runAnimTrack = cat_animator:LoadAnimation(runanim)
local connection = nil
local playing = false
game.Players.PlayerAdded:Connect(function(p)
p.CharacterAdded:Connect(function(c)
local DISTANCE = 15
local plrHum:Humanoid = c:FindFirstChildOfClass("Humanoid")
local hrp = c:WaitForChild("HumanoidRootPart")
local function update()
local mag = (hrp.Position - catHRP.Position).Magnitude
local direction = (hrp.Position - catHRP.Position).Unit
local angleinRads = math.atan2(direction.Z, direction.X)
if mag < DISTANCE then
-- if i did +angleinRads instead of -angleinRads, if i moved left, it would rotate the npc right. - math.rad(90) faces
--the npc towards me instead of having his side profile facing toward my character.
catHRP.CFrame = CFrame.new(catHRP.Position) * CFrame.Angles(0, -angleinRads - math.rad(90), 0)
if not playing then
runAnimTrack:Play()
playing = true
end
else
runAnimTrack:Stop()
playing = false
end
end
connection = rs.Stepped:Connect(update)
plrHum.Died:Connect(function()
connection:Disconnect()
end)
end)
end)
changes i made to get the npc to face me and not bug out:
local direction = (hrp.Position - catHRP.Position).Unit
local angleinRads = math.atan2(direction.Z, direction.X)
if mag < DISTANCE then
-- if i did +angleinRads instead of -angleinRads, if i moved left, it would rotate the npc right. - math.rad(90) faces
--the npc towards me instead of having his side profile facing toward my character.
catHRP.CFrame = CFrame.new(catHRP.Position) * CFrame.Angles(0, -angleinRads - math.rad(90), 0)