I'm trying to make a part only face the target's direction only by the X-Axis while the part is moving towards the target with tweening. I tried mashing 2 functions together (the tween moving function and direction facing function) but obviously, it didn't work.
Code:
faceTarget = function(target, torso)
if target ~= nil then
local BG = Instance.new("BodyGyro")
BG.MaxTorque = Vector3.new(0, math.huge, 0)
BG.P = 7500 -- // The point of this is to set the speed of how fast the AI turns
BG.Parent = torso
end
end
chaseAfter = function(zombie, torso)
while true do
wait()
local target = findNearestTorso(torso.Position)
if target ~= nil then
local info = TweenInfo.new(math.random(10))
local goal = {}
goal.CFrame = target.CFrame
faceTarget(target, torso)
local tween = tweenService:Create(torso, info, goal)
tween:Play()
end
end
end

1 comment
it worked, but the only problem is that the zombies are facing backwards...