Speed variable not working

Godot Version

4.3

Question

i have this code.

extends CharacterBody2D

@export var SPEED := 300.0
@export var JUMP_VELOCITY := -400.0
@export var GRAVITY := 1200.0

func _physics_process(delta: float) -> void:
	# Apply gravity
	if not is_on_floor():
		velocity.y += GRAVITY * delta


	playermove()
	playerjump()

	# Move character
	move_and_slide()

func playermove():
	var direction := Input.get_axis("A Left Key", "D Right Key")
	if direction != 0:
		velocity.x = direction * SPEED
	else:
		velocity.x = move_toward(velocity.x, 0.0, SPEED)

func playerjump():
	if Input.is_action_just_pressed("ui_accept") and is_on_floor():
		velocity.y = JUMP_VELOCITY

Why does my speed variable in the inspector not affect player movement? I must be missing something, but I can’t seem to figure out why.

My player is a characterbody2D with a collisionshape2D. i dragged my player scene to the level scene.

Do you change the speed variable, and then immediately press F5/F6/whatever GUI button to test the scene?

If so: after changing the variable in the inspector, click somewhere else in the screen (for instance, in the code editor of a script you have open), then save the scene and press F5/F6/the GUI button.

1 Like

i don’t have GUI buttons on my level right now. I only have a character and I move it with the A and D keys. But what is the purpose of what you are saying? What is it supposed to do? This sounds like a weird solution to get a value in the inspector to work.

What @TokyoFunkScene is saying is that if you click in a text field in the inspector (or several other places in Godot), what you type in doesn’t get “committed” until you take focus back away from that text field. If you click on your “speed” field, type in a different number, and then immediately run the game, it may still use the old value.

1 Like

godot is such a wierd engine. im so used to unity that i miss small stuff like this

Well, it is an open source engine; you can always contribute a fix if you find it irksome enough…