The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

+1 vote

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.

Godot version 3.2.3
in Engine by (13 points)

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

1 Answer

0 votes

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 (8,550 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 Frequently asked questions and 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 [email protected] with your username.