Sign in to confirm you’re not a bot
This helps protect our community. Learn more
How To Make 2D Knockback In Godot
87Likes
1,720Views
Nov 162024
Hello everybody, today I made 2d knockback in Godot which as always you can find on my discord at the about section. Hope you enjoined watching. Feel free to comment. Make sure to like, share, and of course subscribe! See you next time. Code: extends CharacterBody2D @export var speed = 300.0 @export var min_knockback := 100 @export var slow_knockback := 1.1 var knockback:Vector2 func _physics_process(delta: float): if knockback.length() "more then" min_knockback: knockback /= slow_knockback velocity = knockback move_and_slide() return var direction := Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down") if direction: velocity = direction * speed else: velocity.x = move_toward(velocity.x, 0, speed) velocity.y = move_toward(velocity.y, 0, speed) move_and_slide() Area2D: extends Area2D @export var knockback := 1000 func _on_body_entered(body: Node2D): body.knockback = position.direction_to(body.position) * knockback

Follow along using the transcript.

Godot Guru

2.69K subscribers