Can't make bullets move to the left

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

I’m currently programming an enemy who can use an attack that fires bullets from the left and right sides of the screen. Unfortunately, while the bullets firing from the left are able to move to the right. The right-spawning ones can’t move to the left. Depending on how I try to alter my code they either stand still like their movement is being cancelled out, or they move to the left and off the screen.

position -= transform.x * bullet_speed * delta does not work.

Is there a way to easily fix this, or am I going to have to revamp my movement code? I’m using an Area2D for the bullets, so I can’t use move_and_slide.

Apologies if the answer is obvious, I’m tired and haven’t been on Godot for a month.

How is the on_right variable being set / controlled?

jgodfrey | 2022-08-13 15:35

Oh, it’s being controlled by it’s parent, the enemy. I have two functions for whether the bullet’s spawning on the left or right, and only the left-spawning function switches the on_right variable to false, so it moves in the right direction.

uncannyvilla | 2022-08-13 18:35

:bust_in_silhouette: Reply From: yrtv

I have two functions for whether the bullet’s spawning on the left or
right, and only the left-spawning function switches the on_right
variable

Switch variable in both functions.

I tried that and it didn’t fix the problem. The right-spawning bullets just held still. But I think I just found the reason why, I just don’t know how to fix it…

I erased my bullet’s movement code in the _physics_process function, and they still moved, just more slowly… I think the script is calling both it’s own _physics_process function and the one from the script it’s inheriting, causing it both to move faster and cancel it’s movement when trying to go left, as the inherited script is only meant to go right.

I thought the inherited script’s functions get overrided when you add them to the other script? does it not work when it comes to the _process functions?

uncannyvilla | 2022-08-14 00:36