I have started making a 3D Tile based farming game in Godot (inspired from Homegrown). I managed to make the Random Terrain and Camera systems on my own but am now struggling to make the terrain editing thing.
So the world is generated in tiles of primarily Grass, Farm and Pavement. Now I need a way to edit these tiles in the game by clicking on it. Although I have a logic in my mind, I am unable to implement it.
I need the access the tile by clicking on it with a mouse (I am a super beginner).
I am using this code to generate the world:
extends Node3D
var world_tile_array = []
@export var world_size = 10
var space_between_tile = 1
var generate_modes = ["Grass", "Pave", "Farm"]
func world_tile_array_generate(world_size):
var soil_tiles = load("res://scenes/tiles.tscn")
var tiles = []
for i in range(world_size):
for j in range(world_size):
var tile = soil_tiles.instantiate()
tile.position.x = i
tile.position.z = j
tile.set_mode(generate_modes.pick_random())
tiles.append(tile)
return tiles
func world_generate(tiles):
for i in tiles:
$Tiles.add_child(i)
func _ready():
world_tile_array = world_tile_array_generate(world_size)
world_generate(world_tile_array)
In the comments is the logic which I came up with and the world which is generated.
Please reference the video. How can I get a similar result?