Need help with character not falling or moving. SOLVED I was just really dumb

Code:

‘’’

extends CharacterBody3D

#How fast the character is moving.

var SPEED = 5.0

var JUMP_VELOCITY = 4.5

func _physics_process(delta: float) -> void:

\# Add the gravity.``

\if not is_on_floor():``

\velocity += get_gravity() * delta``

\# Handle jump.``

\if Input.is_action_just_pressed("space") and is_on_floor():``

\velocity.y = JUMP_VELOCITY``

\# Get the input direction and handle the movement/deceleration.``

\# As good practice, you should replace UI actions with custom gameplay actions.``

\var input_dir := Input.get_vector("right", "left", "down", "up")``

\var direction := (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()``

\if direction:``

\velocity.x = direction.x * SPEED``

\velocity.z = direction.z * SPEED``

\else:``

\velocity.x = move_toward(velocity.x, 0, SPEED)``

\velocity.z = move_toward(velocity.z, 0, SPEED)``

\move_and_slide()`


`

‘’’

Heres a screen shot of what happens when I play the TestWorld scene.

r/godot - Movement code not working with character staying in the air. Any Help appreciated.|750xauto

I appreciate any help, please be nice im kinda new, Thx.

Something weird happened when you formatted your code and it’s unreadable.

You need to use tick marks like this:

```gd
#Code here
```

And it will format like this:

#Code here

I think you may have used apostrophes: ‘’’

Is "space” the name of an action, registered by you? Or, is your intension to say “when the SPACE key is pressed“?

Your code mean the former; if you want the latter, use Input.is_key_pressed(KEY_SPACE) or Input.is_physical_key_pressed(KEY_SPACE). You can read about their differences in the docs.

If you indeed want the former, make sure you’ve actually created the actions, see here (I suggest you probably name it “jump“ or something).

Godot allows passing input events to “actions” (which are just names that you set up in the Input Map), then checking, in your code, for actions instead of bare inputs. This extra layer enables key binding at runtime (so your players can define how to “jump”, to their preference), plus you can bind more than one input event to a single action and check the one action to check them all.

Im using the space key as an action, the reason I dont use jump is because I want to leave room to use the jump key for other actions, kinda like OOT if you play the old zelda games. Thx for the help.

I made a reddit post that I think has a better format for the code. https://www.reddit.com/r/godot/comments/1t6p70q/character_not_moving_falling_or_taking_input/

You can assign any number of actions to the same key.

I would double check the jump velocity. It seems tiny to me and it may be that the jump is too small for you to notice it. Increase it to a few hundred just to see if it works.

Can u please screenshot what your mapped actions are in your project settings?