I don't know how to make the player shoot a bullet downwards, I can instance the bullet but I don't know how to make the bullet rotate for move down. Shooting left and right works fine.
Player Script:
if Input.is_action_just_pressed("Shoot") && can_shoot == true && !Input.is_action_pressed("ui_down"):
var bullet = Bullet.instance()
if sign($Position2D.position.x) == 1:
bullet.set_bullet_direction(1)
if sign($Position2D.position.x) == -1:
bullet.set_bullet_direction(-1)
get_parent().add_child(bullet)
bullet.position = $Position2D.global_position
current_bullets -= 1
print (current_bullets)
if Input.is_action_just_pressed("Shoot") && can_shoot == true && on_ground == false && Input.is_action_pressed("ui_down"):
var bullet = Bullet.instance()
get_parent().add_child(bullet)
velocity.y = Jump_Power
current_bullets -= 1
print (current_bullets)
if current_bullets == 0:
can_shoot = false
Bullet Script:
extends Area2D
const Speed = 1000
var velocity = Vector2()
var direction = 1
func _ready():
pass
func set_bullet_direction(dir):
direction = dir
if dir == -1:
$Sprite.flip_h = true
func _physics_process(delta):
velocity.x = Speed * delta * direction
translate(velocity)
func _on_VisibilityNotifier2D_screen_exited():
queue_free()
func _on_Bullet_body_entered(_body):
queue_free()
Sorry if this is poorly formatted, its my first time using the Q&A. Any help would be greatly appreciated