Question about 2D movement not working

I just started using Godot recently and I cant get the Characterbody2D basic movement working and I’m not sure what to do

2 Likes

There are a ton of tutorials on YouTube. Look them up and follow them.

I have done that but its the same thing it doesn’t say there isn’t anything wrong with the script but it just freezes and I cant move around

1 Like

Be more specific about your exact problem, and boil down the code to the minimum necessary to demonstrate the problem you’re having.

im using an animatedsprite2D with the template movement script for the code but ive also tried codes ive found on youtube but it wont move around

What’s a template movement script? Post the smallest code example that demonstrates the problem. My working day is about to start, so I won’t have much time to help further, but someone else may be able to if you provide enough, but not too much, information.

extends CharacterBody2D

const SPEED = 300.0
const JUMP_VELOCITY = -400.0

Get the gravity from the project settings to be synced with RigidBody nodes.

var gravity = ProjectSettings.get_setting(“physics/2d/default_gravity”)

func _physics_process(delta):
# Add the gravity.
if not is_on_floor():
velocity.y += 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()

h bjh

To make it easier for people who may be able to help, post your code in a way that is more easily readable. See pennyloafer’s example in the discussion at How to optimize spawning thousands of objects

having the same problem following Brackeys tutorial.

seems almost like when you run or debug your game , Godot wont recognize keyboard inputs yea?

im not sure im watching the same tutorial aswell but if you figure it out please let me know

It needs to be a CharacterBody2D.

AnimatedSprite2D is just the art component.

I had that issue early in my learning of Godot.

I’ve ended up setting in Input Map (Project → Project Settings) for all of my work.

For anyone following the Brackeys tutorial and still struggling. Check if you attached your camera to your Game-scene or your Player-scene. If it’s attached to the wrong scene, you won’t see your character falling because the camera is following it.

3 Likes

thank you! that was my problem!