How to prevent bullet is moving down during jumping?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By bellhwi

When I press fire key during jumping,
the bullet is instantiated on the air and moving forward for a bit,
but then it goes down.
How can I fix it?

Thank you for any comments!

player code

extends KinematicBody2D

func fire():
	var projectile = load("res://Projectile.tscn")
	var bullet = projectile.instance()
	add_child_below_node(get_tree().get_root().get_node("Stage"), bullet)

bullet code

extends KinematicBody2D

var velocity = Vector2()
const SPEED = 2500

func _ready():
	velocity.x = SPEED
	
func _physics_process(delta):
	if position.x > SPEED / 2:
		queue_free()
	move_and_slide(velocity)
:bust_in_silhouette: Reply From: ramazan

try.
get_parent().add_child(bullet)
or get_parent().get_parent().add_child(bullet)
don’t let the player be a child