This commit is contained in:
JISAUAY committed 2025-07-25 11:28:47 -05:00
commit 3626379b23
3 files changed
+118

No files matched your search

+51
View File
@@ -0,0 +1,51 @@
TrackEnemy = {}
TrackEnemy.__index = TrackEnemy
function TrackEnemy:new(model, name, health, speed)
local self = setmetatable({}, TrackEnemy)
self.model = model
self.name = name
self.health = health
self.speed = speed
self.alive = true
self.currentWaypoint = 1
return self
end
function TrackEnemy:damage(amount)
self.health = self.health - amount
if self.health <= 0 then
self.alive = false
self:die()
end
end
function TrackEnemy:die()
print(self.name .. " has died.")
if self.model then
self.model:Destroy()
end
end
function Trackenemy:moveToWaypoints(waypoints, dt)
if not self.currentWaypoint then self.currentWaypoint = 1 end
local target = waypoints[self.currentWaypoint]
if target then
local currentPos = self.model.PrimaryPart.Position
local targetPos = target.Position
local direction = (targetPos - currentPos).Unit
local distance = (targetPos - currentPos).Magnitude
local step = self.speed * dt
if distance <= step then
self.model.SetPrimaryPartCFrame(CFrame.new(targetPos))
self.currentWaypoint = self.currentWaypoint + 1
else
self.model:SetPrimaryPartCFrame(
CFrame.new(currentPos + direction + step)
)
end
end
end
+37
View File
@@ -0,0 +1,37 @@
local RunService = game:GetService("RunService")
local Waves = require(script.Parent.Waves)
local waypoints = { -- Fill with your waypoint Parts
workspace.Waypoint1,
workspace.Waypoint2,
workspace.Waypoint3,
-- etc.
}
local enemies = {} -- Table to hold TrackEnemy objects
local function spawnWave(waveData)
coroutine.wrap(function()
for _, group in ipairs(waveData) do
for i = 1, group.count do
local enemyModel = group.model:Clone()
enemyModel.Parent = workspace
local enemy = TrackEnemy:new(enemyModel, group.name, group.health, group.speed)
end
if group.delay and group.delay > 0 then
wait(group.delay)
end
end
end)()
end
spawnWave(Waves[1])
RunService.Heartbeat:Connect(function(dt)
for i, enemy in ipairs(enemies) do
if enemy.alive then
enemy:moveToWaypoints(waypoints, dt)
end
end
end)
+30
View File
@@ -0,0 +1,30 @@
local Wave = {
{
{
model = workspace.EnemyModel,
name = "Enemy",
health = 100,
speed = 10,
count = 5
}
},
{
{
model = workspace.FastEnemyModel,
name = "FastEnemy",
health = 50,
speed = 20,
count = 10
},
{
model = workspace.EnemyModel,
name = "Enemy",
health = 100,
speed = 10,
count = 3,
delay = 0
},
}
}
return Waves