can't get get_slide_colision() to work properly

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

Hi guys. I’ve been trying to make a ball bounce with vector math (I know I could just look at the cases where it bounces of a wall and of the ground independently but where’s the fun in that amirite).

The first bounce is working fine, but when it hits the ground for the 2nd time I get a null instance error, get_slide_collision(0) doesn’t exist.

Any ideas why that’s happening?

extends KinematicBody2D

const gravity = 10
const bounce_force = 700
const friction = 0.047
const friction_ratio = 75

# do not change ----------------
var sprite_rotation_speed = friction/friction_ratio
#               ----------------

var motion = Vector2(0,0)
var normal = Vector2(0,-1)

var gravity_multiplier = 1
var rotation_force = 0

func _physics_process(delta):
	
	motion.y += gravity * gravity_multiplier
	if test_move(global_transform, delta*motion):
		print("testmove")
		var aux_motion = motion;
		
		motion = move_and_slide(motion, normal)
		
		motion = aux_motion.bounce(get_slide_collision(0).normal).normalized()*lerp(bounce_force, 0, motion.angle_to(aux_motion)/PI)
	

	else:
		motion = move_and_slide(motion, normal)
	if get_slide_count() > 0:
		print("Slide_Count")