How do I script reset horizontal velocity of a player

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

I’ve recently got recommended Godot for a project and I started scripting for my player node. My problem happens when I try to reset my horizontal velocity of the player (vel.x = 0) for this player node which for reference I used this 2020 article How to Make a Complete Game With Godot[1]

[1]: .
Here’s my script:


var speed : int = 200 
var jumpForce : int = 600 
var gravity : int = 800 

var vel : Vector2 = Vector2() 
var grounded : bool = false 


onready var sprite = $Sprite 
func _physics_process (delta) : 

#reset horizontal velocity

vel.x = 0

#movement inputs

if Input.is_action_pressed("move_left") :
vel.x -= speed
if Input.is_action_pressed("move_right") :
vel.x += speed
# applying the velocity

vel = move_and_slide(vel, Vector2.UP)

… and so on like in the article
Without this line of code my left and right movement script will show up as an error so I was wondering if anybody can find my solution. Though there is probably a Q&A like this somewhere I can’t find it. Thanks sincerly.

:bust_in_silhouette: Reply From: magicalogic

You don’t seem to have indented the code inside the _physics_process function.
Also remove the pass statement from the function.