0 votes

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]: https://godottutorials.pro/how-to-make-games-godot/ .
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.

Godot version Godot version 3.4
in Engine by (12 points)

1 Answer

+1 vote

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

by (2,017 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.