0 votes

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 moveandslide.

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

Godot version 3.4
in Engine by (12 points)

How is the on_right variable being set / controlled?

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.

1 Answer

0 votes

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.

by (889 points)

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?

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.