The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

0 votes

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

Godot version v3.3.2
in Engine by (12 points)

Please log in or register to answer this question.

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 Frequently asked questions and 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 [email protected] with your username.