Tile mesh around player and scroll

I made a tiled water mesh in Blender with a displacement texture. What I want to do is make a bunch of them tile around the player and constantly move in a certain direction until they are far away and show up on the other side to give an impression of rippling water. If you’ve played games like Blox Fruits that have infinite scrolling water, I’m trying to do that but with meshes, not textures. I tried typing up a script but I couldn’t come up with a way to make each tiled scroll without referencing clones individually.

Water Mesh

As you can see, the mesh is quite large and I only want 9 squares of water around the player at all times, as they will also be inside.

1 Like

Are you looking for a way to dynamically tile and move multiple instances of your water mesh around the player in a game environment, similar to the infinite scrolling water effect seen in games like Blox Fruits?

1 Like

Yes, and also make the tiling change based on the player’s position on the XZ plane. I’ll make a diagram (yes i made it in GIMP bad choice):
metal tear

1 Like
-- Define variables
local waterTile = game.Workspace.WaterTile -- Reference to the water tile model
local player = game.Players.LocalPlayer -- Reference to the local player
local tileSize = 10 -- Size of each water tile
local tileCount = 3 -- Number of tiles to have around the player in each direction
local tiles = {} -- Table to store references to spawned water tiles

-- Function to spawn water tiles
local function SpawnWaterTiles()
    for x = -tileCount, tileCount do
        for z = -tileCount, tileCount do
            local newTile = waterTile:Clone() -- Clone the water tile model
            newTile.Parent = game.Workspace -- Set the parent to the Workspace
            newTile.Position = Vector3.new(x * tileSize, 0, z * tileSize) -- Set the position of the new tile
            table.insert(tiles, newTile) -- Add the new tile to the tiles table
        end
    end
end

-- Function to update water tiles based on player position
local function UpdateWaterTiles()
    local playerPos = player.Character and player.Character.HumanoidRootPart.Position -- Get player position
    if playerPos then
        for _, tile in ipairs(tiles) do
            -- Calculate distance between player and tile
            local distance = (playerPos - tile.Position).magnitude
            -- Check if tile is far enough from player to be moved to the other side
            if distance > tileSize * tileCount * math.sqrt(2) then
                -- Move tile to the other side
                local offset = playerPos - tile.Position
                tile.Position = tile.Position + offset
            end
        end
    end
end

-- Call the functions
SpawnWaterTiles()
game:GetService("RunService").RenderStepped:Connect(UpdateWaterTiles) -- Update water tiles every frame

This script assumes you have a model named “WaterTile” in your Workspace that represents the water mesh. Adjust the tileSize and tileCount variables to fit your desired tile size and number of tiles around the player.

This is so complete; thanks a ton! You really made that fast as well.

Of course, I’m happy I could help. I copied part of it from one of my old scripts :sweat_smile:

Just ensure you keep it clean and possibly add something to obscure it a bit so the transition is clean between tiles being generated.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.