So like I own a TD game and like I wanna optimise this way further… Haven’t tried using the BezierPath module yet but I just wanna get some general feedback on how I can optimise this. Doesn’t use Humanoids btw.
function mob.LerpTo(newMob, target)
local alpha = 0
local startCFrame = newMob.Mover.Position
local loop = nil
local reachedTarget = Instance.new("BindableEvent")
local distance = (newMob.Mover.Position - target).Magnitude
loop = RunService.Heartbeat:Connect(function(delta)
if newMob and newMob:FindFirstChild("Config") then
local speed = newMob:GetAttribute("Speed")*workspace.Info.Timescale.Value
local relativeSpeed = distance / speed
local goalCFrame = startCFrame:Lerp(target, alpha)
if newMob.Config:FindFirstChild("DontTurn") then
if newMob.Config:FindFirstChild("DontTurn").Value == true then
local lookAtCFrame = CFrame.lookAt(newMob.Mover.Position, Vector3.new(target.X,target.Y,target.Z))
TweenService:Create(newMob.Mover, TweenInfo.new(.2, Enum.EasingStyle.Sine), { CFrame = lookAtCFrame }):Play()
end
else
local lookAtCFrame = CFrame.lookAt(newMob.Mover.Position, Vector3.new(target.X,target.Y,target.Z))
TweenService:Create(newMob.Mover, TweenInfo.new(.2, Enum.EasingStyle.Sine), { CFrame = lookAtCFrame }):Play()
end
newMob.Mover.Position = goalCFrame
alpha += delta / relativeSpeed
if alpha >= 1 then
loop:Disconnect()
reachedTarget:Fire()
end
else
loop:Disconnect()
end
end)
reachedTarget.Event:Wait()
end
function mob.Move(newMob, map, XZOffset, oldmovepoint, oldLane)
local Root = newMob.PrimaryPart
local newPos
local waypoints
local previouspoint=1
if oldLane and oldLane ~=0 then
waypoints = map.Waypoints[oldLane]
else
waypoints = map.Waypoints[newMob.WaypointNumber.Value]
end
if oldmovepoint and oldmovepoint~=0 then
previouspoint = oldmovepoint
end
for waypoint=previouspoint, #waypoints:GetChildren() do
newMob.MovingTo.Value = waypoint
if waypoint == 1 then
else
if waypoints[waypoint]:FindFirstChild("A") and waypoints[waypoint]:FindFirstChild("B") then
for t = 0,1,0.025 * (newMob:GetAttribute("Speed")*workspace.Info.Timescale.Value) do
local waypoint1 = waypoints[waypoint].Position
local waypoint2 = waypoints[waypoint].A.Position
local waypoint3 = waypoints[waypoint].B.Position
newPos = interpolation.QuadBezier(waypoint1,waypoint2,waypoint3,t)
mob.LerpTo(newMob,Vector3.new(newPos.X + XZOffset,newPos.Y,newPos.Z + XZOffset))
end
else
newPos = waypoints[waypoint].Position
mob.LerpTo(newMob,Vector3.new(newPos.X + XZOffset,newPos.Y,newPos.Z + XZOffset))
end
end
end
local enemyStats = EnemyDataModule.Enemies[newMob.Name]
workspace.Info.Timescale:GetPropertyChangedSignal("Value"):Connect(function()
newMob.Humanoid.WalkSpeed = (enemyStats.Speed - 0.5 or 1)
print("Speed Changed.")
end)
takeDamageEvent:FireAllClients()
map.Base.Humanoid:TakeDamage(newMob:GetAttribute("Health"))
newMob:Destroy()
end--]]