How do i get a KinematicBody2D's speed before a collision happens?

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

I want to get whatever speed I had right before I hit a wall. What i’m doing right now is
if is_on_wall():
if my_speed.x < 100:
do this
do that
But i get “34” or “-34”.

AFAIK KinematicBody2D doesn’t have a speed of its own because you are supposed to handle that yourself… so it’s up to you to have that speed, isn’t it? Otherwise how did you move your object in the first place? Maybe there is a bug or misunderstanding in your own code?

Zylann | 2019-09-30 12:55

I am moving it with move_and_slide(), i’m giving it a Vector2() value on the x whenever i press “a” or “d” and then using move_and_slide(), i just want to get whatever that number was right before i hit a wall, the only way i can think of it is using is_on_wall() but by that point the Vector2().x gets set to 0 because i want it to stop.

orange_boi | 2019-09-30 18:35