Does anyone know how to squeeze and stretch a sprite based on the linear_velocity of a rigidbody2D?

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

I tried using the code below but it doesnt seem to work as intended. Im trying to make a really bouncy ball projectile that will change shape depending on its speed. Any advice would really help!

func _integrate_forces(state):
var counter = [false,false,false,false]
var veclocity = abs(linear_velocity.y)
print(veclocity)

if veclocity >= 400:
	if counter[0] == false:
		$Skin.scale.y += 0.025
		counter[0] = true
	if veclocity >= 600:
		if counter[1] == false:
			$Skin.scale.y += 0.025
			counter[1] = true
		if veclocity >= 800:
			if counter[2] == false:
				$Skin.scale.y += 0.025
				counter[2] = true
			if veclocity >= 1000:
				if counter[3] == false:
					$Skin.scale.y += 0.025
					counter[3] = true

if veclocity <= 1000:
	if counter[0] == true:
		$Skin.scale.y -= 0.025
		counter[0] = false
	if veclocity <= 800:
		if counter[1] == true:
			$Skin.scale.y -= 0.025
			counter[1] = false
		if veclocity <= 600:
			if counter[2] == true:
				$Skin.scale.y -= 0.025
				counter[2] = false
			if veclocity <= 400:
				if counter[3] == true:
					$Skin.scale.y -= 0.025
					counter[3] = false
:bust_in_silhouette: Reply From: Ando

You´re thinking too complex.
Try something like this:

$Skin.scale.y = 1 + abs(velocity.y/400)

This worked, thank you so much! lol I really did complicate it

GeckoDev | 2022-08-06 13:16

:bust_in_silhouette: Reply From: the_maven

Animation is a lot easier.
You will just create the sprites variations and change them as you fit.