Unidirectional bullet poblem -- How can I make Area2d shoot both ways?

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

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

extends Area2D
const RAPIDPACE = 300
func _ready():
    set_process(true)

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?

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?

raymoo | 2018-02-23 01:51

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.

koigx | 2018-02-23 08:55