How do i create a code for my platformer character that allow the player to run jump and walk

Godot Version 4.3

I tried looking up every possible answer but i can’t find or figure out how to code my player character to run jump walk and stay still when motionless please help

The basic platformer template does that, it seem like you are rather close to that template. What did you want to change in it? Could you paste your entire script between three ticks instead of screen shotting?

The error on line 9 is so strange I would recommend deleting the entire line, I’m not sure what you wanted to get out of that. You can’t create a variable with parenthesis in it’s name and the name you’ve almost given it matches a Input function which is strange.

k i edited my code a bit but now the player won’t move and jump and the animation is the only thing that works
extends CharacterBody2D

@onready var _animated_sprite = $AnimatedSprite2D

var speed = 750.0

func _physics_process(delta):
velocity = Vector2.ZERO

if Input.is_action_pressed("ui_right"):
	velocity.x += 5.0 * speed
	if velocity.y == 0.0:
		_animated_sprite.play("walk")
		if Input.is_action_just_released("ui_right"):
			_animated_sprite.stop()

if Input.is_action_pressed("ui_left"):
	velocity.x -= 5.0 * speed
	if velocity.y == 0.0:
		_animated_sprite.play("walk")
		if Input.is_action_just_released("ui_right"):
			_animated_sprite.stop()

if Input.is_action_pressed("ui_up"):
	velocity.y -= 1.0 * speed

Seems wildly different, why not start with the basic template, as you had before?

extends CharacterBody2D


const SPEED = 300.0
const JUMP_VELOCITY = -400.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()

Now let’s try to insert your animations

extends CharacterBody2D

@onready var animated_sprite: AnimatedSprite2D = $AnimatedSprite2D

const SPEED = 300.0
const JUMP_VELOCITY = -400.0


func _physics_process(delta: float) -> void:
	if not is_on_floor():
		velocity += get_gravity() * delta

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

	var direction := Input.get_axis("ui_left", "ui_right")
	if direction:
		# player is walking
		animated_sprite.play("walk")
		velocity.x = direction * SPEED
	else:
		# no input; stopping
		animated_sprite.stop()
		velocity.x = move_toward(velocity.x, 0, SPEED)

	move_and_slide()

i changed because i don’t think that would work with my world build

It looks like a platformer world, I think the basic template will work quite well for this game. Have you tried it? Did anything go wrong?

yes i tried it and my character glitched like crazy when i tried movement earlier today

k now i tried again the player sprite just falls through the ground everytime i run it

Can you provide more insight to how it “glitched like crazy”? It’s a tried and true script, I’m quite surprised. Your player looks set up correctly, hard to tell if the tilemap has collision, but that’s the only non-script issue I could see.

Ok yeah the tilemap needs collision added to it.

it still falls through the ground


Nice, a physics layer has been added, but have you assigned any tiles to have collision? Check your TileSet panel and a little further down in the doc I linked.

thanks, it took a while to figure out how even with the docs but it works now thank you I’m just beginning with Godot and you have been very patient and kind

Tilemaps are kind of tricky, especially since they were just updated in 4.3; I still don’t know how to set up the auto tiler!

Good luck, have fun!