fix max height on a constant bouncing kinematicbody2d

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

hi, i got this scene with 4 staticbodies and its respective collision shapes limiting top, down, left and right screen position, and a kinematicbody2d with its collision shape;

found this code twice in an old question here and in godot docs introduction to vectors, except by one line code its identical so more or less i grasp it.

kinematicbody2 constant bounces as expected and it keeps the force, so each bounce get same height.
if i drop kinematic body at posy 80 it bounce back at posy 80, if i drop it at 150 it bounces back at 150.

but what i want to achieve is that it bounce back at a desired height indepently where it was dropped, so if i droped it at 150 i want it to bounce back at 80 and keep same height each time, what do i need?.

extends KinematicBody2D

var velocity = Vector2(60,0) #horizontal and vertical forces

func _ready():
pass

func _physics_process(delta):
velocity.y += 500 * delta #vertical applied force
var collision = move_and_collide(velocity * delta)
if collision:
var motion = collision.remainder.bounce(collision.normal)
velocity = velocity.bounce(collision.normal)
#velocity.y = -400 #cheating here without success
move_and_collide(motion)
pass