Grid movement demo finetune

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By verbaloid

I used one of the demos (Grid movement) for my game, but in the demo the movement of Actor to another grid cell is instant. I’m using this template to create a kind of slide-show, where each cell takes entire screen and the player is simply jumping from cell to cell, so I made the Pivot invisible (using it only to trigger collision shapes).
I need the transition from cell to cell to be smooth, using interpolation and easing.

What should I add to this, to make the Actor interpolate smoothly the movement to target position?

extends "pawn.gd"

onready var Grid = get_parent()

func _ready():
update_look_direction(Vector2(1, 0))

func _process(delta):
var input_direction = get_input_direction()
if not input_direction:
	return
update_look_direction(input_direction)

var target_position = Grid.request_move(self, input_direction)
if target_position:
	move_to(target_position)
else:
	bump()

func get_input_direction():
return Vector2(
	int(Input.is_action_pressed("ui_right")) - int(Input.is_action_pressed("ui_left")),
	int(Input.is_action_pressed("ui_down")) - int(Input.is_action_pressed("ui_up"))
)

func update_look_direction(direction):
$Pivot/Sprite.rotation = direction.angle()

func move_to(target_position):
set_process(false)
$AnimationPlayer.play("walk")

# Move the node to the target cell instantly,
# and animate the sprite moving from the start to the target cell
var move_direction = (target_position - position).normalized()
$Tween.interpolate_property($Pivot, "position", - move_direction * 32, Vector2(), $AnimationPlayer.current_animation_length, Tween.TRANS_LINEAR, Tween.EASE_IN)
position = target_position

$Tween.start()

# Stop the function execution until the animation finished
yield($AnimationPlayer, "animation_finished")

set_process(true)


func bump():
set_process(false)
$AnimationPlayer.play("bump")
yield($AnimationPlayer, "animation_finished")
set_process(true)
:bust_in_silhouette: Reply From: njamster

but in the demo the movement of Actor to another grid cell is instant.

No it isn’t! The actors position is tied to the grid, thus updated in discrete jumps of 32 pixels (the grid size). However, the movement of the pivot-node (i.e. the part the player sees) is animated. Check out the video for a more detailed explanation.

Unlike the demo itself, I’m making a sort of slide-show, where each cell is a slide that takes entire screen. So the player simply jumps from cell to cell.
I made the pivot-node invisible for the player (it’s just used to enter collision_shape in each cell to trigger different graphics).
What I need is the very movement of player’s view to be smooth, interpolated.

Sorry, that I didn’t explain it in the post.

So, is there an easy way to interpolate the actor’s position?

Thanks again for the answer!

verbaloid | 2020-05-16 10:39

Can I just

$Tween.interpolate_property($Actor

instead of $Pivot?

verbaloid | 2020-05-16 11:45

Yes. However, as the script is attached to the Actor-node it would be:

$Tween.interpolate_property(self, ...)

Also make sure to remove the line after that: position = target_position.

njamster | 2020-05-17 12:45