I'm super new to godot and programing in general. so Im struggling with making my enemies. I got the player to shoot just fine, but now I am stuck. The game is an auto runner platformer, so the player is running to the right, and the enemies are facing left. I am using one bullet instance for both player and enemy so when It does fire it travels right and ends up killing itself. What I want to happen is for it to fire to the left in a straight line when the player is close enough.

heres my code for the enemy:
and the bullet code in case thats also being a little ankle bitter:

  • Toxe replied to this.
  • JankBone like @Toxe says, change velocity to match the desired direction. How you do this is up to you - you could create a bullet scene variation and set its speed to -speed so it goes the other way (and use that in enemy), or perhaps have a start method that accepts a speed, called with the appropriate value, e.g. Vector2.LEFT (for the enemy) and then in start:

    func start(Vector2 direction) -> void:
        velocity = direction * SPEED

    Or rotate the whole thing so velocity.x is the other way 😉

    (also, you only need to do it once)

    JankBone If an enemy is shooting the bullet set the direction to Vector2.LEFT.

      Or make sure the bullet's forward vector is facing the right way.

        Toxe unfortunatly it didnt work, it still wants to go right for some odd reason.

        • Toxe replied to this.

          JankBone You need to respect the direction in your _physics_process() function when you set the velocity. The way it is now velocity.x is always positive.

          JankBone like @Toxe says, change velocity to match the desired direction. How you do this is up to you - you could create a bullet scene variation and set its speed to -speed so it goes the other way (and use that in enemy), or perhaps have a start method that accepts a speed, called with the appropriate value, e.g. Vector2.LEFT (for the enemy) and then in start:

          func start(Vector2 direction) -> void:
              velocity = direction * SPEED

          Or rotate the whole thing so velocity.x is the other way 😉

          (also, you only need to do it once)

          Cool! I ended up making a second bullet scene with the adjustments suggested and that worked! Thank you both @spaceyjase and @Toxe