Add Player Movement animation to the target cell

This commit is contained in:
CactiChameleon9 2022-07-16 09:14:20 +01:00
parent 24cc1b8f04
commit 263d323d58
2 changed files with 22 additions and 2 deletions

View File

@ -1,3 +1,17 @@
extends Node2D
export var starting_pos : Vector2 = Vector2.ZERO
export var map_position : Vector2 = Vector2.ZERO
var target_position : Vector2 = Vector2.ZERO
var moving : bool = false
func _physics_process(delta):
# If the 2 positions are close enough, then not moving
moving = false if target_position.round() == position.round() else true
if not moving: return
#TODO: Replace with tween magic
position += (target_position - position)/2.5

View File

@ -25,5 +25,11 @@ func _physics_process(delta):
if movement_queue.find(Vector2.ZERO) != -1:
movement_queue.remove(movement_queue.find(Vector2.ZERO))
if len(movement_queue) == 0:
return
#move the character once space in the queue if not moving
if not $Player.moving:
$Player.map_position += movement_queue.pop_front()
$Player.target_position = $TileMap.map_to_world($Player.map_position)
$Player.target_position += $TileMap.cell_size/2