![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
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]: https://godottutorials.pro/how-to-make-games-godot/ .
Here’s my script:
#physics
var speed : int = 200
var jumpForce : int = 600
var gravity : int = 800
var vel : Vector2 = Vector2()
var grounded : bool = false
#componets
onready var sprite = $Sprite
func _physics_process (delta) :
pass
#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.