3D Movement not Working, no Error in the Debugger

Godot Version

Version 4.2

Question

I’m new to coding. VERY new. I tried coding 3D character movement, but when I run the scene in the debug menu, nothing happens.
It would be greatly appreciated if someone could help me figure out what went wrong. My code is shown below. Thank you!


@export var speed = 5.0
@export var acceleration = 4.9
@export var jump_speed = 8.0

var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
var jumping = false
var last_floor = true

@onready var spring_arm = $SpringArm3D
@onready var model = $Rig
@onready var anim_tree = $AnimationTree
@onready var anim_state = $AnimationTree.get("parameters/playback")

func _physics_process(delta):
	velocity.y += -gravity * delta
	get_move_input(delta)
	
	move_and_slide()
	
func get_move_input(_delta):
	var direction = Vector3.ZERO
	if Input.is_action_pressed("ui_right"):
		direction.x += 1
	if Input.is_action_pressed("ui_left"):
		direction.x -= 1
	if Input.is_action_pressed("ui_up"):
		direction.z += 1
	if Input.is_action_pressed("ui_down"):
		direction.z -= 1
	
	if is_on_floor() and not last_floor:
		jumping = false
		anim_tree.set("parameters/conditions/grounded", true)
	last_floor = is_on_floor()
	
	if not is_on_floor() and not jumping:
		anim_state.travel("Jump_Idle")
		anim_tree.set("parameters/conditions/grounded", false)

	if is_on_floor() and Input.is_action_just_pressed("jump"):
		velocity.y = jump_speed
		jumping = true
		anim_tree.set("parameters/conditions/grounded", false)
	anim_tree.set("parameters/conditions/jumping", jumping)

Where do you use this script? CharacterBody3D ?
If possible, you should compress the project and upload it here (max. 4 MB). Hard to say without knowing the scene where the error could be.

e.g. the editor shows which nodes are still missing, hold the mouse pointer over the icon

1 Like

Linear velocity is a managed variable.

Use _integrate_forces as your process loop for precise control of the body state.

Or even better, use forces if you don’t need to set the velocity directly, which you shouldn’t need to.

1 Like

Hi! Sorry for the late reply, I posted this at the end of my work on it for today while I was frustrated.
It was in the CharacterBody3D node. Was that the wrong place for it to be?

There can be multiple correct solutions. :slight_smile: Your error description was incomplete for me.

It’s best to try what @Efi wrote. If you get stuck with this, it would be better to compress your project with Zip and share it here or in your cloud. This could significantly reduce troubleshooting.