CharacterBody2D: Basic Movement Template question

Godot Version

4.4.1

Question

I am using a tutorial to complete a 2D game, and it suggested using this template to move the sprite. The problem is it moves and jumps too fast. The tutorial suggests changing the speed and jump velocity from 300, -400 to 130 and -300 respectively like so:

extends CharacterBody2D

const SPEED = 130.0
const JUMP_VELOCITY = -300.0

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("ui_accept") 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 direction := Input.get_axis("ui_left", "ui_right")
if direction:
	velocity.x = direction * SPEED
else:
	velocity.x = move_toward(velocity.x, 0, SPEED)

move_and_slide()

The problem is changing the speed and jump veolcity doesn’t change the character’s speed at all, I’ve tried changing these variables in all sorts of ways, it apparently has no effect. Can anyone help me with this? Thank you.

Please put your code between two sets of ``` marks, one on a line above, and another the line below.

Try making the values 1 and -1. See if that changes them at all. If so, tweak to your heart’s content. If not, then something else is going on.

As far as I can tell there isn’t an issue with the code, as presented. I’d try an engine restart then verify that your character’s is_on_floor() is returning true when you believe it is. It’s possible the gravity is affecting your velocity if your character isn’t accurately detecting the floor.

Thank you for your responses. The character floor code seems to be working, even after engine restart. Changing to negative values also doesn’t seems to impact the movement. Here’s what the game looks like right now:

"extends CharacterBody2D

const SPEED = 830.0
const JUMP_VELOCITY = -800.0

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("ui_accept") 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 direction := Input.get_axis("ui_left", "ui_right")
if direction:
	velocity.x = direction * SPEED
else:
	velocity.x = move_toward(velocity.x, 0, SPEED)

move_and_slide()"

Blockquote

Even after changing the velocity variables there’s no change. Does anyone else have this problem? Thank you.

You may have a duplicate of your script somewhere and you are editing the wrong one, make sure to click on the script icon for your CharacterBody2D to edit it’s script specifically.

Success! Thank you for the suggestions, but it turns out that the issue was when Godot updated to 4.4, the main menu when starting a new project had three options that didn’t exist before, setting it to the default “Forward+” was what was causing the issues. When I started the project under the renderer labeled “Compatability” I had no issues and was able to complete the entire game tutorial.