From 3626379b23d4f099fe83a3c45a269fdc891a4f29 Mon Sep 17 00:00:00 2001 From: JISAUAY Date: Fri, 25 Jul 2025 11:28:47 -0500 Subject: [PATCH] init --- TrackEnemy.lua | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ TrackLogic.lua | 37 ++++++++++++++++++++++++++++++++++++ Waves.lua | 30 +++++++++++++++++++++++++++++ 3 files changed, 118 insertions(+) create mode 100644 TrackEnemy.lua create mode 100644 TrackLogic.lua create mode 100644 Waves.lua diff --git a/TrackEnemy.lua b/TrackEnemy.lua new file mode 100644 index 0000000..1bed92e --- /dev/null +++ b/TrackEnemy.lua @@ -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 + diff --git a/TrackLogic.lua b/TrackLogic.lua new file mode 100644 index 0000000..c940918 --- /dev/null +++ b/TrackLogic.lua @@ -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) diff --git a/Waves.lua b/Waves.lua new file mode 100644 index 0000000..482a03c --- /dev/null +++ b/Waves.lua @@ -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