0 votes

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:
    _player.play('walk_up')
    velocity.y -= 1
elif direction == Direction.RIGHT:
    _player.play('walk_right')
    velocity.x += 1
elif direction == Direction.DOWN:
    _player.play('walk_down')
    velocity.y += 1
elif direction == Direction.LEFT:
    _player.play('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.

Godot version 3.2.3
in Engine by (12 points)

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

1 Answer

+1 vote

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.

by (6,922 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.