Escoria - Player scale (depth)

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By bobokox
:warning: Old Version Published before Godot 3 was released.

hey!

is there a way to scale the size of the player while walking to imitate depth?

thank you!

:bust_in_silhouette: Reply From: bobokox

For all who have the same problem:

in the player script define this variables at the beginning:

export var depth = 0.00
onready var player_spr = get_node("sprite")
onready var pl_scale = player_spr.get_scale()
var pl_pos0 = get_global_pos()

at the end of the function _process(time):

var pl_pos = get_global_pos()
var diff = pl_pos.y - pl_pos0.y
var scale_x = pl_scale.x * ((diff/1000)*depth+1)
var scale_y = pl_scale.y * ((diff/1000)*depth+1)
player_spr.set_scale(Vector2(scale_x, scale_y))

the pivot point of your player sprite should be set on the middle of the bottom of the sprite for correct scaling.
the intense of scaling can be controlled with the export variable “depth” (0 = no scaling).
on if depth is set to high, it will flip your player sprite, so be careful.

hope this will help someone!