How to load bullets in linear line for ui and animate it like this clip

Godot Version 4.1.3

How to load bullets in linear line for ui and animate it like this clip

bullet load concept idea Iwoc_devloglowlowULTRACOMPRESS
(trail part is a bug and the gif looks glitchy but I hope you get the idea)
I would like to know how to do this
previously I tried to use array to instantiate them but I don’t know how to animate them as well, should I appened these to an array or something? idk


Edit: I just got an idea to code maybe I should put a number to count how much bullet it loads so the first bullet goes to left and if number get +1 higher the previous bullet get 30pixel to left and the next one do the same
but don’t know exactly if this method is good or not
leave a reply and tell what is the better way and proper way to do it?
maybe using tween? idk how to use that…

1 Like

To make this a whole lot easier for you maybe try making the bullets fly in from the side

So when a new bullet is loaded have a loop like this:

const step_count = 10 # the lower this number, the faster the animation
const loaded_bullet_start_position = 100 # shortened to "lbs"
const distance_between_loaded_bullets = 100 # shortened to "lbd"
const final_bullet_positions = [lbs+lbd*0, lbs+lbd*1, lbs+lbd*2, lbs+lbd*3] # length is max magazine size

var loaded_bullet_nodes = []

func add_new_bullet(b): # b needs to be an instance of the magazine bullet node
 var b_hop = final_bullet_positions[loaded_bullet_nodes.size()]/float(step_count)
 var bullet_hop = float(distance_between_loaded_bullets)/float(step_count)
 for i in step_count:
  b.position.x -= b_hop
  for bullet in loaded_bullet_nodes: bullet.position.x -= bullet_hop
 yield(get_tree(), "idle_frame")

This needs constant frametime to be nice, otherwise you would have to create tweens
Dont forget to set the correct y position :wink:

1 Like

Thank you so much for your help
I didn’t even expect to get reply for my problem so I was thinking about removing this feature from my game but thanks to you I won’t. Your code are kinda new to me but it kinda makes sence and I’m happy to find a new thing to learn. I can’t thank you more but I will credit you as a helper in programming in my credit list of game :heart: I wish you luck and hapiness

  • Soroosh
1 Like

Thank you haha, I wish you success!