My question: Is there a way to make it do smoother turns when facing a player and at the same time, not having something that moves itself (CFrame.lookAt makes the zombie jitter when moving)? Is there an alternative? (I’m trying to make the zombie lock at the nearest player.
You can modify your zombies to use ControllerManagers, which gives a FacingDirection property, but you can also use an AlignPosition and rotate the Attachment linked to it, the official Rthro Drooling Zombie does this.
local npc = script.Parent
local playerService = game:GetService(“Players”)
local detectionRadius = 20
local followSpeed = 10
function findNearestPlayer()
local nearestPlayer = nil
local nearestDistance = detectionRadius
for _, player in pairs(playerService:GetPlayers()) do
local distance = (npc.Position - player.Character.HumanoidRootPart.Position).Magnitude
if distance < nearestDistance then
nearestPlayer = player
nearestDistance = distance
end
end
return nearestPlayer
end
function onHeartbeat()
local targetPlayer = findNearestPlayer()
if targetPlayer then
local direction = (targetPlayer.Character.HumanoidRootPart.Position - npc.Position).unit
npc:MoveTo(npc.Position + direction * followSpeed * (1 / 60))
end
This code doesn’t turn the zombie to face the player through? It just makes it walk in a straight line towards them.
Actually, the zombie probably shouldn’t be fully turning towards the player, because they might not be moving in a straight line to them if pathfinding is use. Really, the zombie should turn it’s head and torso to look at the player more naturally, but it depends on what OP wants. Personally, a zombie strafing while looking straight at me just doesn’t look quite right to me.
Maybe OP wants to make CS style bots or create a more general enemy AI with guns, but idk how a zombie would work at that point unless you want bots with knives come at you, strafing and jumping like CS 1.6 bots or PD2 zombie faction
Humanoids are instances anyway, and it’s not like you need to interact with any extra instances outside of setting ControllerManager.FacingDirection as you can just use the officially-provided example scripts.
This is the easiest way to go that I have discovered, I haven’t come across a method as simple and functional as this.
You should use the Example scripts, which creates the ControllerManager and all the other necessary components for the character of every player that joins.