How do I change sprite size for perspective?

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

I am new to Godot and game creation in general and I was having trouble figuring out how I would change the size/scale of a sprite when walking further away or closer to screen.

I found something similar here:

(Even though it is for renpy they both use similar code to python.)

I tried looking online, for the most part, I read something about how you can’t change the size of a kinematic body and I should use a node?

I ended up going back and forth and getting really confused by the end of searching.

:bust_in_silhouette: Reply From: flurick

So every thing in the scene is a Node, the “Sprite” is just a type of Node.
For the purpose of what is seen in the video it should be enough to map the position directly to the scale of the same Sprite-Node. Something like this:

extends Sprite

func _process(delta):

    #just to get the sprite to move at all in my test
	position = get_global_mouse_position() 
    #how far down are we on the screen (between 0.0 and 1.0)
	var amount = position.y / get_viewport().size.y

    #apply the scale to this same sprite in both x and y direction
	scale.x = 1 + amount
	scale.y = scale.x