Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | EugenioTC |
Hello, I’m following this tutorial but my situation is my robot won’t move right instead it’ll move left(even though it’s set to the right), both my up input key and left input key do what intended. Below I have the pdf I’m using to learn(page 24), and the code pasted from the project.
chrome-extension://efaidnbmnnnibpcajpcglclefindmkaj/https://godottutorials.pro/wp-content/uploads/2020/07/Godot-Game-Development-for-Beginners.pdf
extends KinematicBody2D
stats
var score : int = 0
physics
var speed : int = 200
var jumpforce : int = 600
var gravity : int = 800
var vel : Vector2 = Vector2()
var grounded : bool = false
components
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)
gravity
vel.y += gravity * delta
jump input
if Input.is_action_pressed("jump") and is_on_floor():
vel.y -= jumpforce
sprite direction
if vel.x < 0:
sprite.flip_h = true
elif vel.x > 0:
sprite.flip_h = false