Godot Version
4.4
Question
im making my first platformer and i accidentally erased my player walking left to right when making a ladder set up. heres the code for the player
extends CharacterBody2D
const SPEED = 100.0
const CLIMB_SPEED = 80.0
const JUMP_VELOCITY = -250.0
var gravity = ProjectSettings.get_setting(“physics/2d/default_gravity”)
var ladder_on =false
@export var upSpeed := 40
func on_body_exited(body: Node2D) → void:
pass # Repla
func _physics_process(delta: float) → void:
if not is_on_floor():
velocity.y += gravity * delta
func CheckLadderAndTakeAction():
if ladder_on == true:
if Input.is_action_pressed(“move_up”):
velocity.y -= upSpeed
elif Input.is_action_pressed(“move_down”):
velocity.y == upSpeed
func _on_ladder_body_entered(body):
ladder_on = true
pass
func _on_ladder_body_exited(body):
ladder_on = false
pass
func _physics_process(delta):
var input_direction = Vector2(
Input.get_axis("move_left", "move_right"),
var velocity = Vector2.ZERO
if Input.is_action_just_pressed("jump") and is_on_floor():
velocity.y = JUMP_VELOCITY
var direction = Input.get_axis("move_left", "move_right")
if direction:
velocity.x = direction * SPEED
$AnimatedSprite2D.play("walk")
$AnimatedSprite2D.flip_h = direction < 0
else:
velocity.x = move_toward(velocity.x, 0, SPEED / 7)
$AnimatedSprite2D.play("idle")
if not is_on_floor():
$AnimatedSprite2D.play("jump")
move_and_slide()
Thank you so much