How would one go about making a pogo-bounce-attack like in Hollow Knight?

Godot Version



I am very new to Godot and wanna learn the engine by making a small platformer game where the main mechanic revolves around bouncing on spikes and enemies to traverse the level, kinda like the Path of Pain in Hollow Knight. But since I am so new to programming in general, I have no idea how I would go about making an attack that bounces the player off of objects. Any tips would be greatly appreciated!

I already have this code to make the character move, as well as a scene with some platforms.

extends CharacterBody2D

@export var SPEED = 700.0
@export var JUMP_VELOCITY = -1000.0
@export var SMALL_JUMP_VELOCITY = -200.0
@export var gravity = 3000

# Main function, called every frame.
func _physics_process(delta):
	# Variable for movement. 
	var horizontal_direction = Input.get_axis("move_left", "move_right")
	# Add the gravity.
	if not is_on_floor():
		velocity.y += gravity * delta
	# Handle jump.
	if Input.is_action_just_pressed("jump") and is_on_floor():
		velocity.y = JUMP_VELOCITY 
	# Handle small jump.
	if Input.is_action_just_released("jump"):
		if velocity.y < SMALL_JUMP_VELOCITY:
			velocity.y = SMALL_JUMP_VELOCITY
	# Handle movement.
	if horizontal_direction:
		velocity.x = horizontal_direction * SPEED
		velocity.x = move_toward(velocity.x, 0, SPEED)

Have you tried just calling the same “small jump” code when you confirm that you have hit an enemy?

If you don’t have confirmation of hit on enemies, you’ll want to look into raycast and Area2d and get that setup.

Swing sword
Confirm sword hit
Apply velocity.y

Should be about it.

1 Like

I don’t have an attack system yet, the code in the post is everything I currently have. Do you have any recommendations on where to learn the systems you mentioned? Also, if I wanted to have the player bounce off of walls on the X-axis, how would I go about coding that? Since I guess that wouldn’t work with the jump code