I want to move all instances (after being spawned) by some distance each time my player shoots a bullet.
extends KinematicBody2D
var motion = Vector2(10,0)
var current_pos = self.global_position # saved current position
func _ready():
self.global_position = Vector2(85, 490)
#starting position when spawned
func _process(delta):
if Global.is_step == true:#true when player shoots a bullet
current_pos = self.global_position
# save current position each time for each instance
set_physics_process(true)
Global.is_step = false
func _physics_process(delta):
if self.global_position.x < current_pos.x + 100:
self.global_position += motion
I wanted to spawn each instance one by one when the player shoots. But the above code works only for the first instance produced and the rest of them stay in the position where they were spawned. I tried using 'self' but it still doesn't work. I am a beginner godot game developer so I'd like you to help me out with this.