Godot Version
v4.2.2.
Hi, I’m new in Godot and I’m still learning GDscript. I watched several tutorials about wall jumping but still wall jump pushback is wrong. I think that I should put move_toward somewhere, but I don’t really know where. Here’s my code. I would be grateful if someone could help with this :v
extends CharacterBody2D
@export var speed : int = 500
@export var jump_force : int = 610
@export var gravity : int = 900
var wall_jump_pushback = 1000
var is_wall_sliding = false
var wall_slide_gravity = 150
func _physics_process(delta):
var direction = Input.get_axis("Lewo", "Prawo")
if direction :
velocity.x = direction * speed
if is_on_floor():
$AnimatedSprite2D.play("RUNNING")
else:
velocity.x = 0
if is_on_floor():
$AnimatedSprite2D.play("default")
#Rotacja
if direction == 1:
$AnimatedSprite2D.flip_h = false
elif direction == -1:
$AnimatedSprite2D.flip_h = true
#Grawitacja
if not is_on_floor():
velocity.y += gravity * delta
if velocity.y > 0:
$AnimatedSprite2D.play("FALLING")
#Skok
if Input.is_action_just_pressed("Skok"):
if is_on_floor():
velocity.y -= jump_force
$AnimatedSprite2D.play("JUMPING")
if is_on_wall_only() and Input.is_action_pressed("Prawo"):
velocity.y -= jump_force
velocity.x -= -wall_jump_pushback
if is_on_wall_only() and Input.is_action_pressed("Lewo"):
velocity.y -= jump_force
velocity.x -= wall_jump_pushback
move_and_slide()
wall_slide(delta)
func wall_jump():
pass
func wall_slide(delta):
if is_on_wall() and not is_on_floor():
if Input.is_action_pressed(“Lewo”) or Input.is_action_pressed(“Prawo”):
is_wall_sliding = true
else:
is_wall_sliding = false
else:
is_wall_sliding = false
if is_wall_sliding:
velocity.y += (wall_slide_gravity * delta)
velocity.y = min(velocity.y, wall_slide_gravity)