I'm trying to make kind of a smash bros like fighting game but simplier and everything it's working the way that I imagine, except the knockback hit.
I want that when the character knockback with high speed, he bounces on wall.
I'm using a Kinematic Body 2D with the moveandslide.
I've tried to get the collision and multiply the velocity by the collision normal but it just don't make anything.
if velocity.length() > 500:
if get_slide_count() > 0:
velocity = velocity * get_slide_collision(0).normal
I've also tried to use the .bounce() but also dont work :(
if velocity.length() > 500:
if get_slide_count() > 0:
velocity = velocity.bounce(get_slide_collision(0).normal)
When I use a print to check, everything is working, it gets the collision and the normal, it multiplies, it just dont make anything.
I completely sure that I'm making something wrong.
Here's a Preview (the character is the blue one):
Edit: Someone on Reddit have helped me.
It happens that the velocity that I was getting, it'was when the character stop, so i just needed to make a variable with the previous velocity:
var prev_velocity = velocity
velocity = move_and_slide(velocity, UP)
if prev_velocity.length() > 500:
if get_slide_count() > 0:
velocity = prev_velocity.bounce(get_slide_collision(0).normal) * 0.8