+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)
move_and_slide(motion)

set_physics_process(true)
``````

https://youtu.be/jfxfsI6pk-A

in Engine

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!

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

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

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

by (14 points)