Fix player reverting back to default position upon first move

This commit is contained in:
CactiChameleon9 2022-07-17 18:48:34 +01:00
parent c6d26f9b77
commit 8abb393949
2 changed files with 4 additions and 2 deletions

View File

@ -3,8 +3,8 @@
[ext_resource path="res://icon.png" type="Texture" id=1] [ext_resource path="res://icon.png" type="Texture" id=1]
[ext_resource path="res://Characters/Player.gd" type="Script" id=2] [ext_resource path="res://Characters/Player.gd" type="Script" id=2]
[node name="Player" type="Node2D"] [node name="Player" type="Node2D" groups=["OnMap"]]
script = ExtResource( 2 ) script = ExtResource( 2 )
[node name="Sprite" type="Sprite" parent="." groups=["OnMap"]] [node name="Sprite" type="Sprite" parent="."]
texture = ExtResource( 1 ) texture = ExtResource( 1 )

View File

@ -26,6 +26,8 @@ func _ready():
for child in get_children(): for child in get_children():
if child.is_in_group("OnMap"): if child.is_in_group("OnMap"):
child.map_position = $TileMap.world_to_map(child.position) child.map_position = $TileMap.world_to_map(child.position)
child.target_position = $TileMap.map_to_world(child.map_position)
child.target_position += $TileMap.cell_size/2
func do_damage_around_player(damage, damage_range): func do_damage_around_player(damage, damage_range):