0 votes

this is my code:

extends KinematicBody2D

const gravity = 30

export var speed = 120
export var jump_power = 650

var Floor = Vector2(0,-1)
var velocity = Vector2.ZERO
var onground = false

func physicsprocess(delta):

if Input.is_action_pressed("ui_left"):
    velocity.x = -1
    $AnimatedSprite.flip_h = true
elif Input.is_action_pressed("ui_right"):
    velocity.x = 1
    $AnimatedSprite.flip_h = false
else:
    velocity.x = 0

velocity.y += gravity * delta

if Input.is_action_pressed("jump") and onground == true:
    velocity.y = -jump_power
    onground = false

if is_on_floor():
    onground = true
else:
    onground = false

velocity = velocity.normalized() * speed
velocity = move_and_slide(velocity,Floor)
in Engine by (23 points)

1 Answer

0 votes

The problem is that once the velocity is set to negative, it will never become positive again. You shouldn't normalize the velocity in this case since you want your speed to change instead only being 120.

by (7,148 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 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 webmaster@godotengine.org with your username.