Please help me, i can't find the problem

Godot Version

godotv4.3

I’ve made this code for a character, because I want him to move with small jumps that you can charge. But for some reason, it only work properly with the space bar(jump) and the up arrow(make him move following positive y). It does work with the other arrow keys, but not properly. I need to know if this is due to my code (because i know it is quite messy) or something else, because i really don’t know why it doesn’t work.
here is my code:
extends CharacterBody3D

@onready var charge = $Charge
const SPEED = 5.0
const JUMP_VELOCITY = 3.0

func _ready():
charge.value = 0

func _physics_process(delta: float) → void:
charge.visible = false

# Add the gravity.
if not is_on_floor():
	velocity += get_gravity() * delta

_movement()

move_and_slide()

func _movement():
if Input.is_action_pressed(“ui_accept”) and is_on_floor():
charge.value += 3
charge.visible = true
if Input.is_action_just_released(“ui_accept”) and is_on_floor():
velocity.y = JUMP_VELOCITY * charge.value * 0.02
charge.value = 0
charge.visible = false
if Input.is_action_pressed(“ui_left”) and is_on_floor():
charge.visible = true
charge.value += 1.5
if Input.is_action_just_released(“ui_left”) and is_on_floor():
velocity.y = JUMP_VELOCITY * charge.value * 0.02
velocity.x = SPEED * charge.value * -0.015
charge.value = 0
charge.visible = false
if Input.is_action_pressed(“ui_down”) and is_on_floor():
charge.visible = true
charge.value += 1.5
if Input.is_action_just_released(“ui_down”) and is_on_floor():
velocity.y = JUMP_VELOCITY * charge.value * 0.02
velocity.z = SPEED * charge.value * 0.015
charge.value = 0
charge.visible = false
if Input.is_action_pressed(“ui_right”) and is_on_floor():
charge.visible = true
charge.value += 1.5
if Input.is_action_just_released(“ui_right”) and is_on_floor():
velocity.y = JUMP_VELOCITY * charge.value * 0.02
velocity.x = SPEED * charge.value * 0.015
charge.value = 0
charge.visible = false
if Input.is_action_pressed(“ui_up”) and is_on_floor():
charge.visible = true
charge.value += 1.5
if Input.is_action_just_released(“ui_up”) and is_on_floor():
velocity.y = JUMP_VELOCITY * charge.value * 0.02
velocity.z = SPEED * charge.value * -0.015
charge.value = 0
charge.visible = false
elif is_on_floor():
velocity.x = move_toward(velocity.x, 0, SPEED)
velocity.z = move_toward(velocity.z, 0, SPEED)
pass

Please format your code with a code block, three back ticks

```
#Your code here
```

1 Like

hello,
the reason the up arrow and the spacebar are the only ones working is because of the elif statement at the bottom of the movement function, this only affects the up arrow if-statement. it might work if you make it an if statement instead of elif or if you copy and paste it for all the other if-statements.

1 Like

Thanks for ur help! It wasn’t really how i solve the problem, i just needed to make the elif statement an if statement, and then put it at the beginning of my function!