#I'm making an isometric game

1 messages · Page 1 of 1 (latest)

royal palm
#

I don't know if I'm letting myself be understood but I wanted to know that, I want him to only walk in the center of the blocks and to walk in an isometric way, and not in the 4-sided way that we all know in 2D games.

royal palm
#

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

boreal badger
#

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
royal palm
#

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

boreal badger
royal palm
#

not work