Godot Version
4.2.1
Question
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
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
move_and_slide()