Hey, and thanks for reading in advance.
I’m attempting to add a function to a module that returns a list of all possible cells (assuming no obstructions occur) that are within range that the player can move to from a given cell, and for the given example, I’m assuming the player can move two cells in any combination of directions.
Trouble is, the number of permutations goes up exponentially as you add on more ‘movement points’ to the character, and I’m having trouble thinking of how to create a loop that goes through every single possibility.
Code:
local PS = game:GetService("PhysicsService")
local CS = game:GetService("CollectionService")
local TerrainParams = RaycastParams.new()
TerrainParams.CollisionGroup = "Default"
--
local TileLibrary = {}
TileLibrary.WORLD_HEIGHT = 0
TileLibrary.WORLD_OFFSET = Vector2.new(2, 2)
TileLibrary.TILE_AREA = Vector2.new(4, 4)
function TileLibrary:TileVector(x, y, height)
local Plane = (Vector2.new(x, y) * TileLibrary.TILE_AREA) + TileLibrary.WORLD_OFFSET
local Vector = Vector3.new(Plane.X, height or TileLibrary.WORLD_HEIGHT, Plane.Y)
local FloorCheck = workspace:Raycast(
Vector + Vector3.new(0, 495, 0),
Vector3.new(0, -500, 0),
TerrainParams
)
if FloorCheck and FloorCheck.Instance then
Vector = Vector3.new(Plane.X, FloorCheck.Position.Y, Plane.Y)
end
return Vector
end
function TileLibrary:NearestTile(Vector)
local snapTo = Vector2.new(
math.floor(Vector.X / TileLibrary.TILE_AREA.X),
math.floor(Vector.Y / TileLibrary.TILE_AREA.Y)
)
return TileLibrary:TileVector(
snapTo.X, Vector.Y, snapTo.Y
)
end
function TileLibrary:ConstructCircle(x, y, radius)
local tileCoordinates = {}
-- Code Here
return tileCoordinates
end
return TileLibrary
Does anyone have any ideas I could try? Any help or advice is appreciated.