init
This commit is contained in:
commit
3626379b23
3 files changed
+118
No files matched your search
@@ -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
|
||||
|
||||
Reference in new issue
Block a user