Grid-based movement

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

How would I implement a player movement based on a grid? I tried to find this on docs but no success… I’m very new to Game design.

I have a standard movement code, which works:

func _move(direction: int, delta: float)->void:
velocity = Vector2()
in_movement = true

if direction == Direction.UP:'walk_up')
	velocity.y -= 1
elif direction == Direction.RIGHT:'walk_right')
	velocity.x += 1
elif direction == Direction.DOWN:'walk_down')
	velocity.y += 1
elif direction == Direction.LEFT:'walk_left')
	velocity.x -= 1

velocity = velocity.normalized() * speed

_player.position += velocity * delta

What I’m trying to do is simple: think of the old Pokémon games, the character always walks 1 full tile (NxN) when you input, and can’t be interrupted in the middle of the process (4-way movement)

If anyone could help I’d appreciate it! Thanks.

Have you looked at something like this? Have you also looked at the grid-based movement in the asset library?

Ertain | 2021-03-29 17:08

:bust_in_silhouette: Reply From: exuin

It might be better to use a Tween node for something like this since the player doesn’t have to be checking for input on every frame.