From a7ce7f9796ebb89b89181593886fcb42d6533cb1 Mon Sep 17 00:00:00 2001 From: JISAUAY Date: Fri, 25 Jul 2025 14:42:50 -0500 Subject: [PATCH] add range indicator when placing towers --- TrackLogic.lua | 55 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/TrackLogic.lua b/TrackLogic.lua index 9f2f472..311863b 100644 --- a/TrackLogic.lua +++ b/TrackLogic.lua @@ -1,4 +1,6 @@ local RunService = game:GetService("RunService") +local UserInputService = game:GetService("UserInputService") + local Tower = require(script.Parent.Tower) local Waves = require(script.Parent.Waves) @@ -46,6 +48,8 @@ local waypoints = { -- Fill with your waypoint Parts local selectedTowerType = towerTypes[1] local enemies = {} -- Table to hold TrackEnemy objects local towers = {} +local placingTower = false +local rangeIndicator = nil function selectTowerType(index) selectedTowerType = towerTypes[index] @@ -79,9 +83,57 @@ local function isOnTrack(position) return false end +local function showRangeIndicator(position, range) + if not rangeIndicator then + rangeIndicator = Instance.new("Part") + rangeIndicator.Name = "RangeIndicator" + rangeIndicator.Shape = Enum.PartType.Cylinder + rangeIndicator.Anchored = true + rangeIndicator.CanCollide = false + rangeIndicator.Transparency = 0.6 + rangeIndicator.Color = Color3.fromRGB(100, 200, 255) + rangeIndicator.Material = Enum.Material.Neon + rangeIndicator.Size = Vector3.new(range * 2, 0.2, range * 2) + rangeIndicator.Parent = workspace + -- Rotate so cylinder is flat + rangeIndicator.Orientation = Vector3.new(0, 0, 90) + end + rangeIndicator.Size = Vector3.new(range * 2, 0.2, range * 2) + rangeIndicator.Position = Vector3.new(position.X, position.Y + 0.1, position.Z) + rangeIndicator.Visible = true +end + +local function hideRangeIndicator() + if rangeIndicator then + rangeIndicator:Destroy() + rangeIndicator = nil + end +end + +RunService.RenderStepped:Connect(function () + if placingTower then + local mouse = game.Players.LocalPlayer:GetMouse() + local position = mouse.Hit.p + showRangeIndicator(position, selectedTowerType.range) + else + hideRangeIndicator() + end +end) + +UserInputService.InputBegan:Connect(function(input, gameProcessed) + if gameProcessed then return end + if input.KeyCode == Enum.KeyCode.T then + placingTower = not placingTower + print("Tower Placing Mode:", placingTower and "ON" or "OFF") + if not placingTower then + hideRangeIndicator() + end + end +end) + UserInputService.InputBegan:Connect(function (input, gameProcessed) if gameProcessed then return end - if input.UserInputType == Enum.UserInputType.MouseButton1 then + if input.UserInputType == Enum.UserInputType.MouseButton1 and placingTower then local mouse = game.Players.LocalPlayer():GetMouse() local position = mouse.Hit.p if not isOnTrack(position) then @@ -94,6 +146,7 @@ UserInputService.InputBegan:Connect(function (input, gameProcessed) selectedTowerType.effect ) table.insert(towers, tower) + hideRangeIndicator() end end end)