0 votes

The bullet works, but only in one direction! Here is my code:

extends Area2D
const RAPIDPACE = 300

func _ready():

func _process(delta):
     var speed_x = 8
     var speed_y = 0
     var movement = Vector2(speed_x, speed_y) * RAPIDPACE
     set_position(get_position() + movement * delta)

How can I fix the code to make the bullet shoot both ways?

in Engine by (59 points)

Do you want to make two bullets, one in each direction? Or do you want to be able to control whether the bullet goes to the left or right?

Thanks for the feedback! I'd prefer one bullet that changes directions, but 2 is fine if it's easier. Right now I can get the bullet to shoot the other direction simply by making

speed_x = -8

But all it does is invert the problem: bullet only shoots left. My struggle is to get the bullet to respond to the player changing direction. Each has its scene with its own .gd script.

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 webmaster@godotengine.org with your username.