isometric building

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Naowut

My game has a building element but I can’t really figure out how to do it properly.
Right now I have a tilemap for my world and when I want to place a building I instantiate a scene of that building and set it to the cell position. I guess Im missing access to cell data, like was something build here? But the tilemap doesnt allow cell data. Especially for buildings that are larger than my grid 32x32.

Is there a better way to handle building? I feel like Im going about it all wrong.
Thanks.

Below is some code that I’m playing with but of course I’m open to better solutions.

@export var buildMode = false;
@onready var house = $"../house";
@onready var newHouse = preload("res://house.tscn");

func _process(delta):
	if Input.is_action_just_pressed("Interact"):
		buildMode = !buildMode;
		if buildMode == false:
			house.visible = false;
		else:
			house.visible = true;
	
	if buildMode == true:
		var globalPosition = get_global_mouse_position();
		var worldPosition = self.local_to_map(globalPosition);
		house.position = self.map_to_local(worldPosition);

		if Input.is_action_just_pressed("left_mb"):
			buildMode = false;
			var placedHouse = newHouse.instantiate();
			placedHouse.position = self.map_to_local(worldPosition);
			placedHouse.visible = true;
			get_parent().add_child(placedHouse);

Can you edit your question to include the code for placing the building? You could use the coordinates you retrieve from the TileMap as keys in a Map to track tile data.

Cam | 2023-02-04 19:34

I added some code. But please keep in mind that I’m open to better solutions.

Naowut | 2023-02-04 21:42

I don’t see you accessing cell data at any point in the code.

exuin | 2023-02-28 05:47