Hey guys! I’ve been trying to make a boss fight for the first time, but first and foremost, I want to get the boss moving properly.
Here is the code I have so far:
Code
local range = 50
local PFS = game:GetService("PathfindingService")
local Humanoid = script.Parent:WaitForChild("Humanoid")
local HumanoidRootPart = script.Parent.HumanoidRootPart
local path = PFS:CreatePath()
local WalkAnim = Humanoid:LoadAnimation(script.Walk)
local BossMove1 = Humanoid:LoadAnimation(script.Move1)
local TweenService = game:GetService("TweenService")
local IsWalking = false
function GroundPound ()
local AnimationPound = Humanoid:LoadAnimation(script.Move1)
end
function Playanim()
BossMove1:Play()
script.scream:Play()
end
BossMove1:GetMarkerReachedSignal("Pound"):Connect(function()
print("Found the anim!")
script.scream:Stop()
local PoundRing = game.ServerStorage.BossStuff.Ring:Clone()
PoundRing.CFrame = CFrame.new(script.Parent.RightHand.Position)
PoundRing.Anchored = true
PoundRing.Parent = workspace
PoundRing.Touched:Connect(function(Part)
if Part.Parent:FindFirstChild("Humanoid") and Part.Parent ~= script.Parent then
Part.Parent:FindFirstChild("Humanoid"):TakeDamage(15)
end
end)
local GroundPound = TweenService:Create(PoundRing,TweenInfo.new(3),{Size = Vector3.new(50,0.05,50); Transparency = 1})
GroundPound:Play()
script["Explosion or Crumble"]:Play()
GroundPound.Completed:Wait()
PoundRing:Destroy()
end)
while wait() do
if IsWalking == true then
if WalkAnim.IsPlaying == false then
WalkAnim:Play()
end
elseif IsWalking == false then
WalkAnim:Stop()
end
for i,Player in pairs(game.Players:GetPlayers()) do
if (workspace:WaitForChild(Player.Name).HumanoidRootPart.Position - HumanoidRootPart.Position).Magnitude <= range then
path:ComputeAsync(HumanoidRootPart.Position,Player.Character.HumanoidRootPart.Position)
local waypoints = path:GetWaypoints()
for i,waypoint in pairs (waypoints) do
IsWalking = true
print(path.Status)
if waypoint.Action == Enum.PathWaypointAction.Jump then
Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
end
Humanoid:MoveTo(waypoint.Position)
--Humanoid.MoveToFinished:Wait(2)
end
end
end
end
It works all fine and dandy, however, the movement is sometimes jagged and not straight. There is also an issue with the NPC encountering an obstacle, it wither doesn’t jjump at all, or jumps SEVERAL times making it fly up into the air.
I would also love to get some opinions on how to make it chase other people, this is the solution I came up with , but I’m guessing its poorly optimized having it consistently cyle through players and rerouting paths.
Thanks so much!