@@ -43,3 +43,4 @@ tile_data = PoolIntArray( 0, 0, 0, 1, 0, 0, 2, 0, 0, 3, 0, 0, 4, 0, 0, 5, 0, 0,
[node name="Player" parent="Grid" instance=ExtResource( 2 )]
position = Vector2( 352, 736 )
+gridNode = NodePath("..")
@@ -1,12 +1,17 @@
extends Area2D
# Nodes
-var grid
+export (NodePath) var gridNode
+var grid:TileMap
var tween
var rayFront
var rayLeft
var rayRight
+# Misc
+var cell_size
+var cell_half_size
+
# Enum
const DIR_UP = 0
const DIR_RIGHT = 1
@@ -26,8 +31,10 @@ var is_moving = false
var target_pos
func _ready():
- grid = get_parent()
-
+ grid = get_node(gridNode)
+ cell_size = int (grid.get_cell_size().x)
+ cell_half_size = cell_size / 2
posix = int (position.x / 64)
posiy = int (position.y / 64)
@@ -68,7 +75,7 @@ func _physics_process(delta):
posix += dirx
posiy += diry
- target_pos = Vector2(posix * 64 + 32, posiy * 64 + 32)
+ target_pos = Vector2(posix * cell_size + cell_half_size, posiy * cell_size + cell_half_size)
tween.move_char(self, target_pos)
is_moving = true
tween.start()