Player won't move

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By TomcatLover

I’m very new to Godot, and I was following this tutorial on making my first game → https://youtu.be/Mc13Z2gboEk?list=PLdzc3w91Odff4-FQGgO9hq0N8NhJJHd5l

But despite following all the instructions and using the exact same scripts, line for line, my player just won’t move to the input. I’ve set the input maps correctly and is pressing all the keys that should work, but all it does is fall down and sit still.

Here’s my player script:

extends Actor

func _physics_process(_delta: float) -> void:
	var is_jump_interrupted: = Input.is_action_just_released("jump") and velocity.y < 0.0
	var direction: = get_direction()
	velocity = calculate_move_velocity(velocity, direction, speed, is_jump_interrupted)
	velocity = move_and_slide(velocity, FLOOR_NORMAL)
	
	
func get_direction() -> Vector2:
	return Vector2(
		Input.get_action_strength("move_right") - Input.get_action_strength("move_left"),
		-1.0 if Input.is_action_just_pressed("jump") and is_on_floor() else 0.0
	)
	
func calculate_move_velocity(
		linear_velocity: Vector2,
		direction: Vector2,
		speed: Vector2,
		is_jump_interrupted: bool
	) -> Vector2:
	var out: = linear_velocity
	out.x = speed.x * direction.x
	out.y += gravity * get_physics_process_delta_time()
	if direction.y == -1.0:
		out.y = speed.y * direction.y
	return out

And here’s my actors script:

extends KinematicBody2D
class_name Actor

const FLOOR_NORMAL: = Vector2.UP

export var speed: = Vector2(300.0, 1000.0)
export var gravity: = 3000.0

var velocity: = Vector2(300, 0)

Have I missed something, or is it because I’m using a different version that’s used in the tutorial (3.5.1)? Thank you!

Edited to fix code formatting. In future posts, use the {} button to format code for the forum.

jgodfrey | 2023-01-31 16:17

Are your inputs being triggered appropriately? If you’re not sure, something like this might be helpful…

func get_direction() -> Vector2:
    var vec = Vector2(
        Input.get_action_strength("move_right") - Input.get_action_strength("move_left"),
        -1.0 if Input.is_action_just_pressed("jump") and is_on_floor() else 0.0
    )
    print(vec)
    return vec

With that change, do you see a change in the printed vector when you press the input keys?

jgodfrey | 2023-01-31 18:10