#Needing Help with a grid movement system

1 messages · Page 1 of 1 (latest)

harsh meadow
#

I've made the grid, the player is red.

How would I make grid based movement for the red player to go in adjacent cells?

local Start = Vector3.new(0, 8, 0)
local GridX, GridZ = 8, 8
local CellTable = {
    ["CellFolder"] = Instance.new("Folder")
    }

local PartColor = BrickColor.DarkGray()
local PartSize = Vector3.new(4, 4, 4)

function ChangeColor()
    PartColor = (PartColor == BrickColor.Gray()) and BrickColor.DarkGray() or BrickColor.Gray()
end

function CreateCell(X, Z)
    if Z == 1 then 
    ChangeColor()
    end

    ChangeColor()

    local Part = Instance.new("Part")
    Part.Name = "Cell " .. X .." ".. Z
    Part.BrickColor = PartColor
    Part.Size = PartSize

    Part.Position = Start + Vector3.new(PartSize.X * X, 0, PartSize.Z * Z)

    Part.Anchored = true
    Part.Parent = CellTable["CellFolder"]
    table.insert(CellTable[X],Part)
end

function CreatePlayer()
    local PlayerPosition = CellTable[1][1]
    local PlayerPart = Instance.new("Part")
    PlayerPart.Name = "Player Part"
    PlayerPart.BrickColor = BrickColor.Red()
    PlayerPart.Size = PartSize
    PlayerPart.Position = PlayerPosition.Position + Vector3.new(0,4,0)
    PlayerPart.Anchored = true
    PlayerPart.Parent = workspace
    PlayerValues = {
        ["PlayerPosition"] = PlayerPosition,
        ["PlayerPart"] = PlayerPart
    }
    return PlayerValues
end

function MovePlayer(PlayerValues)
    PlayerValues["PlayerPosition"] = CellTable[1][1]
    PlayerValues["PlayerPart"].Position = PlayerValues["PlayerPosition"].Position + Vector3.new(0,4,0)
end
--Start Builinding Grid
for X = 1, GridX do
    X = {}
    table.insert(CellTable,X)
    for Z = 1, GridZ do
        task.wait()
        CreateCell(#CellTable, Z)
    end
end
CellTable["CellFolder"].Parent = workspace
--Grid Done

print(CellTable)
PlayerValues = CreatePlayer()

while true do
    task.wait(1)
    MovePlayer(PlayerValues)
end
hoary portal
harsh meadow
#

very helpful