How would I make it so the front of the npc always faces the player while it moves?(Not using cframe because it effects the npc’s movement)
NPC:
robloxapp-20230803-2255434.wmv (1.7 MB)
Any help is appreciated
You WOULD use CFrame for this but add a CFrame.Angles() to the end of the positional set.
IE. NPC.CFrame = CFrame.new(Position Magic, Position of Player) or
NPC.CFrame = CFrame.new(Position Magic) + CFrame.Angles(RadX,RadY,RadZ)
This is my current script:
game.Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
local NPC = game.Workspace:WaitForChild("Tank")
local HuamnoidRootPart = NPC.PrimaryPart
local Target = Character
Target = Target:WaitForChild("HumanoidRootPart")
while true do
wait(1)
NPC:SetPrimaryPartCFrame(CFrame.lookAt(HuamnoidRootPart.Position, Target.Position * Vector3.new(1, 0, 1) + HuamnoidRootPart.Position * Vector3.new(0, 1, 0)))
end
end)
end)
But idk where to put the CFrame.Angles() part
I dont think your CFrame.lookAt is doing what you want it to do. The first parameter is the position the part should be and the second is where it should be facing. But in your usage, you have position the same, the target lookAt is some crazy vector math.
Maybe the sum or the difference of the current NPC’s position with the Target’s position as the first parameter, then the position of the Target as the second parameter. since you only need to move the NPC towards the direction of the Target by very small amounts
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.