for some reason, it doesn't generate wall tiles? it's only floor tiles: extends TileMap…
- User
for some reason, it doesn't generate wall tiles? it's only floor tiles:
extends TileMap
Initialize noise generators for different map features
Values between -1 and 1
var moisture = FastNoiseLite.new() var temperature = FastNoiseLite.new() var altitude = FastNoiseLite.new()
Dimensions of each generated chunk
var width = 64 var height = 64
Reference to the player character
@onready var player = get_tree().current_scene.get_node("Player")
List to keep track of loaded chunks
var loaded_chunks = []
func _ready(): # Set random seeds for noise variation moisture.seed = randi() temperature.seed = randi() altitude.seed = randi()
code# Adjust this value to change the 'smoothness' of the map; lower values mean more smooth noise altitude.frequency = 0.01func _process(delta): # Convert the player's position to tile coordinates var player_tile_pos = local_to_map(player.position)
code# Generate the chunk at the player's position generate_chunk(player_tile_pos) # Unload chunks that are too far away. # Note: Not needed for smaller projects but if you are loading a bigger tilemap it's good practice unload_distant_chunks(player_tile_pos)func generate_chunk(pos): for x in range(width): for y in range(height): # Generate noise values for moisture, temperature, and altitude var moist = moisture.get_noise_2d(pos.x - (width/2) + x, pos.y - (height/2) + y) * 10 # Values between -10 and 10 var temp = temperature.get_noise_2d(pos.x - (width/2) + x, pos.y - (height/2) + y) * 10 var alt = altitude.get_noise_2d(pos.x - (width/2) + x, pos.y - (height/2) + y) * 10
code - Assistant
- User
but the thing is I want to use terrain sets not single tiles?
- Assistant
In Godot, terrain sets are handled using autotiling. This means you define a larger texture with all the variations of tiles for different situations, and the autotile algorithm chooses the correct sub-tile based on the surrounding tiles. Your script needs to account for this by setting the appropriate tile index and letting the tile map automatically update the visuals based on your autotile configuration.
- User
- Assistant
- User
res://Scenes/Levels/Map.gd:54 - Parse Error: Unexpected "?" in source. If you want a ternary operator, use "truthy_value if true_condition else falsy_value".
- Assistant
In GDScript, the syntax for a ternary-like operation is:
gdscriptvar value = true_condition if condition else false_conditionThe error you are getting is because GDScript does not support the
? :ternary operator as is used in languages like C++ or Java. Instead, you need to use theifkeyword. Let's correct the usage in your script:Replace this line:
gdscriptvar tile_index = alt < 0 ? 0 : 1 # Incorrect GDScript syntaxwith the proper GDScript syntax:
- User
- Assistant
It looks like there are a couple of issues in the script that needs to be fixed:
- The
set_cellmethod call is incorrect in thegenerate_chunkfunction. - The parameters passed to in the function are also incorrect.
- The