Я работаю над 2-мерной игрой с прокруткой, и я столкнулся с проблемой при попытке реализовать стрельбу в персонажа игрока, раньше это было при стрельбе во время прыжка, он не стреляет, но теперь, когда я нажимаю клавишу прыжка, игрок прыгает вправо, даже если я не нажимаю клавиши направления
вот код
extends KinematicBody2D
const GRAVITY = 20
const SPEED = 200
const JUMP_HIGHT = -550
const UP = Vector2(0,-1)
const SHOOT = preload("res://shoot.tscn")
var motion = Vector2()
var on_ground = false
var is_attacking = false
# warning-ignore:unused_argument
func _physics_process(delta: float) -> void:
motion.y += GRAVITY
if Input.is_action_pressed("right") || is_on_floor() == false:
if is_attacking == false:
motion.x = SPEED
if is_attacking == false:
$Sprite.flip_h = false
$Sprite.play("run")
if sign($Position2D.position.x) == -1:
$Position2D.position.x *= -1
elif Input.is_action_pressed("left") || is_on_floor() == false:
if is_attacking == false :
motion.x = -SPEED
if is_attacking == false:
$Sprite.flip_h = true
$Sprite.play("run")
if sign($Position2D.position.x) == 1:
$Position2D.position.x *= -1
else :
if on_ground == true && is_attacking == false :
$Sprite.play("idle")
motion.x = 0
if Input.is_action_just_pressed("jump"):
if is_attacking == false :
if on_ground == true :
motion.y = JUMP_HIGHT
on_ground = false
if is_on_floor():
if on_ground == false :
is_attacking = false
on_ground = true
else :
if is_attacking == false :
on_ground = false
if motion.y < 0 :
$Sprite.play("jump")
else :
$Sprite.play("fall")
if Input.is_action_just_pressed("shoot") && is_attacking == false:
if is_on_floor() :
motion.x = 0
is_attacking = true
$Sprite.play("attack")
var shoot = SHOOT.instance()
if sign($Position2D.position.x) == 1 :
shoot.set_shoot_direction(1)
else:
shoot.set_shoot_direction(-1)
get_parent().add_child(shoot)
shoot.position = $Position2D.global_position
motion = move_and_slide(motion,UP)
func _on_Sprite_animation_finished() -> void:
is_attacking = false