+1 vote

This is what I have already, but I want to try doing grid-based movement. Any ideas how to do this? This tilemap is not going to change, so I was thinking of having an array that has the center coordinates of every block in the tilemap. Right now I don't have any code for the tilemap, but I did add some sample code to the player.

extends KinematicBody2D

const SPEED = 10000
var motion = Vector2()

# Converts any Vector2 coordinates or motion from the cartesian to the isometric system
func cartesian_to_isometric(cartesian):
    return Vector2(cartesian.x - cartesian.y, (cartesian.x + cartesian.y) / 1.7)

# useful to convert mouse coordinates back to screen-space, and detect where the player wants to know.
# If we want to add mouse-based controls, we'll need this function
func isometric_to_cartesian(iso):
    var cart_pos = Vector2()
    cart_pos.x = (iso.x + iso.y * 2) / 2
    cart_pos.y = - iso.x + cart_pos.x
    return cart_pos

func _physics_process(delta):
    # Everything works like you're used to in a top-down game
    var direction = Vector2()

    if Input.is_action_pressed("ui_up"):
        direction += Vector2(0, -1)
    elif Input.is_action_pressed("ui_down"):
        direction += Vector2(0, 1)

    if Input.is_action_pressed("ui_left"):
        direction += Vector2(-1, 0)
    elif Input.is_action_pressed("ui_right"):
        direction += Vector2(1, 0)

    motion = direction.normalized() * SPEED * delta
    # Isometric movement is movement like you're used to, converted to the isometric system
    motion = cartesian_to_isometric(motion)

func _ready():


in Engine by (13 points)

2 Answers

0 votes

As you were apparently able to find this tutorial how did you manage to not find this one? ;) It's the direct sequel, also from GDQuest, with code on github.

by (10,421 points)

Must of missed it. Thanks a ton!

0 votes

this work for me, the numbers depends of your grid size

extends KinematicBody2D
var inputs = {
"uiright": Vector2.RIGHT,
left": Vector2.LEFT,
"uiup": Vector2.UP,
down": Vector2.DOWN

func unhandledinput(event):
for dir in inputs.keys():
if Input.is
position.x += 8
position.y += 4
if Input.isactionpressed("uileft"):
position.x -= 8
position.y -=4
if Input.is
position.x += 8
position.y -= 4
if Input.isactionpressed("ui_down"):
position.x -= 8
position.y +=4

by (14 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.