If you indent all of the code with a single tab or surround the code in with the ` character (on my keyboard it is the same key as the Tilde key), then it will be formatted as code in your post :smile:
As for the problem, at first glance I'm not 100% sure. On further inspection, and looking through the documentation, I found that get_slide_collision will return the collisions of the last move_and_slide call.
I'm wondering if the problem that there is no collision, and so when you are calling get_slide_collision(0) it is returning null because it didn't collide with anything in the latest move_and_slide call. Unfortunately there does not seem to be any great way to detect whether a KinematicBody2D has collided with something other than using the is_on_InsertSideHere functions. I made a small edit to your script below that may work, though I have not tested so I cannot say for sure.
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)
# Try adding this:
if is_on_ceiling() or is_on_floor() or is_on_wall():
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")
Another thing you could try is checking to see if get_slide_collision(0) is equal to null before trying to access the normal property from it. I'm not sure if that will help with the problem or not, but it's something to try if the code above does not work.
Hopefully this helps!