Best way to make 3D Kinematic Bodies lunge and get knockbacked?

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

What would be the best way to make a player character or an enemy lunge forward when attacking? The best way to add knockback in a game going against the direction you were hit from? Since it’s kinematic I can’t just add a force to push it like a rigidbody, but what is the best method to simulate that?

Knockback effects aren’t that difficult to implement in a KinematicBody2D (or a KinematicBody). A simple way to add a knockback effect is to move the character in the opposite direction it’s moving. If the character is being moved with the vector variable velocity, and it’s only being moved in one direction (for example, being moved on the x-axis), then all that is required is to add a vector in the opposite direction:

# We're pushing the object back on the x-axis.
velocity += Vector2(-100.0, 0.0)

After that, the KinematicBody2D can be moved as normal, such as with move_and_slide().

Ertain | 2022-09-14 00:48