#I'm making an isometric game
1 messages · Page 1 of 1 (latest)
and if you would also be so kind haha, if you could help me place the collisions, this one is from godot 4.3 and I use the TilemapLayer
Yeah, I can give you some pointers on this.
It looks like there's 3 parts to this question.
- Firstly, only allowing movement from the centre of tiles. This can be done using tweens for movement. When the player presses a direction, it creates a tween that will take the character from their current position to the centre of the next tile. After a google search, I found this page, though it's for Godot 3: https://forum.godotengine.org/t/moving-from-tile-to-tile-in-a-grid-like-old-rpgs/27408
- Next, you want isometric movement. There's no settings to toggle for this; it needs to be calculated by hand. Still, with isometric tiles, you know that the centres are half a tile to the side, and half a tile up or down. So you can work this out from the tile size.
I've put together a movement script based on the page I found that should handle both of the above points. It may need tweaking depending on what you're after, but it should hopefully be a starting point:
var moving = false
func _process(delta: float) -> void:
if !moving:
var direction_count = 0
var direction_vector = Vector2i()
if Input.is_action_pressed("ui_up"):
direction_vector += Vector2i(-1, -1)
direction_count += 1
if Input.is_action_pressed("ui_down"):
direction_vector += Vector2i(1, 1)
direction_count += 1
if Input.is_action_pressed("ui_left"):
direction_vector += Vector2i(-1, 1)
direction_count += 1
if Input.is_action_pressed("ui_right"):
direction_vector += Vector2i(1, -1)
direction_count += 1
if direction_count == 1:
var tile_map_layer: TileMapLayer = $"../Floors"
var tile_vector = tile_map_layer.tile_set.tile_size/2
var motion_vector = Vector2(direction_vector.x * tile_vector.x, direction_vector.y * tile_vector.y)
var new_position = position + motion_vector
var tween = get_tree().create_tween()
tween.tween_property(self, "position", new_position, 0.6).set_trans(Tween.TRANS_LINEAR)
tween.tween_callback(func(): moving = false)
moving = true
- Finally, collisions. Unlike most games, you don't really want to use any sort of physics here. You want to know that the tile is blocked before movement even starts. Since you know the tile the player is moving to, you use custom cell tile data to set up whether it's blocked, and only attempt to move there if it's accessible. https://docs.godotengine.org/en/stable/classes/class_tilemaplayer.html#class-tilemaplayer-method-get-cell-tile-data
Inherits: Node2D< CanvasItem< Node< Object Node for 2D tile-based maps. Description: Node for 2D tile-based maps. A TileMapLayer uses a TileSet which contain a list of tiles which are used to creat...
I understand, another question regarding this, is this code here okay? I know it makes me mistake that's why I wanted to know
@boreal badger
get_cell_tile data returns the cell data. So you do something like var tile_data = tile_map.get_cell_tile_data(cell_position)
not work