0 votes

hey!

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

thank you!

in Engine by (95 points)

1 Answer

0 votes
Best answer

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!

by (95 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.