Help about scripts

Godot Version

4.2.1

Question

Hi, i’m new to game dev so i followed a tutorial
https://www.youtube.com/watch?v=1TU2X37wPes and idk why nothing work, i tried to use basic player mouvement template but don’t work either, my sprites can’t move

here my scripts :

extends CharacterBody2D

@export var movement_speed : float = 500
var character_direction : Vector2

func _physics_process(delta):
character_direction.x = Input.get_axis(“right”, “left”)
character_direction.y = Input.get_axis(“forward”, “backward”)
character_direction = character_direction.normalized()
#flip
if character_direction.x > 0: %player_sprites.flip_h = false
elif character_direction.x < 0: %player_sprites.flip_h = true

if character_direction:
	velocity = character_direction * movement_speed
	if %player_sprites.animation != "walking" : %player_sprites.animation = "walking"
else:
	velocity = velocity.move_toward(Vector2.ZERO, movement_speed)
	if %player_sprites.animation != "idle" : %player_sprites.animation = "idle"

	
move_and_slide()

Did you assign inputs to your input map? Do you get any errors?

yes i assigned, and i get no error

now i have a even strange bug
i can’t upload video here so, here the link to the video

What does your script look like now? Remember to paste with code formatting, the </> button or ctrl+e will create three ticks for you like so

```
type or paste code here
```

my script

extends CharacterBody2D



@export var mouvement_speed : float = 500
var character_direction : Vector2



func _ready():
	pass



func _process(delta):
	character_direction.x = Input.get_axis("right", "left")
	character_direction.y = Input.get_axis("forward", "backward")
	character_direction = character_direction.normalized()
	
	#flip
	if character_direction.x > 0: %sprites.flip_h = false
	elif character_direction.x < 0: %sprites.flip_h = true
	
	
	if character_direction:
		velocity = character_direction * mouvement_speed
		if %sprites.animation != "walking": %sprites.animation = "walking"
	else:
		velocity = velocity.move_toward(Vector2.ZERO, mouvement_speed)
		if %sprites.animation != "idle": %sprites.animation = "idle"
		
		
	move_and_slide()
	
	

What is the problem in the video? Wrong animation, or?

When i press my keyboard the player mouve and get back to is previous position, like a elastic, something wrong whith my code ?

Aha! That is indeed weird, nothing in the code you posted should do that… I couldn’t tell because I can’t see in the video what keys are being pressed.

Are there any other scripts in your project? Can you show a screenshot of your scene tree?

That the only scripts

update : i made a new code to try if it work, no it get the same problem, i think godot bug, if it can help i use linux mint with the kernel version : Linux 5.15.0-117-generic x86_64

extends CharacterBody2D



@export var mouvement_speed : float = 500
var character_direction : Vector2
var screen_size


func _ready():
	pass



func _physics_process(delta):
	velocity = Vector2.ZERO # The player's movement vector.
	# Movement input
	if Input.is_action_pressed("right"):
		velocity.x += 1
	if Input.is_action_pressed("left"):
		velocity.x -= 1
	if Input.is_action_pressed("backward"):
		velocity.y += 1
	if Input.is_action_pressed("forward"):
		velocity.y -= 1
		
		
		
	if velocity.length() > 0:
		velocity = velocity.normalized() * mouvement_speed
		

	move_and_slide()
	

Can you upload the project somewhere and link to it, then I can test if I get the same behavior on my windows machine?

https://www.swisstransfer.com/d/503c0928-2301-4042-ad3e-36cdebd4cac1

Looks like you have nothing else in the scene, your player is moving, and the camera follows them so it looks like nothing is happening. Add anything else to the scene beside the player