#Tilemap or not

3 messages · Page 1 of 1 (latest)

fallow garnet
#

i want to make a game where the player is restricted to move on a tilemap, meaning its coordinates should never be between tiles(like in chess), but i want to have smooth animations when moving.
would you make the player a tile in the tilemap or another node, that moves in steps
on one side i dont know how to make smooth moving animation if its a tile, otherwise its harder to interact with the tilemap. what do you reccomend

knotty sundial
# fallow garnet i want to make a game where the player is restricted to move on a tilemap, meani...

I typically make a Node2D with a sprite to represent characters, instead of using a tile on the tilemap.

You can give the Node2D a Vector2 variable named something like grid_pos. Then in _process(), you can lerp the Node2D's built-in position variable to the proper position on the grid. This will give you the smooth movement you want, and all you have to do is change grid_pos - the process function will take care of the rest.

var grid_pos = Vector2(0, 0)
var tile_size = 32

func _process(delta):
    var desired_pos = grid_pos * Vector2(tile_size, tile_size)
    if position != desired_pos:
        position = position.lerp(desired_pos, 0.5)
#

That's for Godot 4, here's Godot 3 (the lerp syntax is changed):

var grid_pos = Vector2(0, 0)
var tile_size = 32

func _process(delta):
    var desired_pos = grid_pos * Vector2(tile_size, tile_size)
    if position != desired_pos:
        position = lerp(position, desired_pos, 0.5)