|
|
|
|
Attention |
Topic was automatically imported from the old Question2Answer platform. |
|
Asked By |
ZSakaro |
extends KinematicBody2D
func _ready():
pass
# physics
var speed : int = 500
var jumpForce : int = 600
var gravity : int = 800
var vel : Vector2 = Vector2()
var grounded : bool = false
# components
onready var sprite = $AnimatedSprite
func _physics_process (delta):
# reset horizontal velocity
vel.x = 0
# movement inputs
if Input.is_action_pressed("move_left"):
vel.x -= speed
$AnimatedSprite.play("run");
elif Input.is_action_pressed("move_right"):
vel.x += speed
$AnimatedSprite.play("run");
else:
vel.x = 0
$AnimatedSprite.play("idle");
# applying the velocity
vel = move_and_slide(vel, Vector2.UP)
# gravity
vel.y += gravity * delta
# jump input
if Input.is_action_just_pressed("jump") and is_on_floor():
$AnimatedSprite.play("up");
vel.y -= jumpForce
# sprite direction
if vel.x < 0:
sprite.flip_h = true
elif vel.x > 0:
sprite.flip_h = false
|
|
|
|
Reply From: |
Gluon |
There are two problems here, the first is you have the check of the jump input after the move and slide has already completed and the second is that it is checking if left and right are in place before checking if the jump is happening.
Put the jump if in the same if block as the rest and make it the first check in that if block (make the move left check the first elif) this should fix it.