Topic was automatically imported from the old Question2Answer platform.
Asked By
HorseGorilla
Hello guys,
There was a problem creating a debuff and applying it to enemies or players. If there is only one debuff, I can float it above the head in the middle of the global position, but the problem is when there are more than one debuff. When there are two, I want to float it by dividing it to the left and right based on the middle, and when there are three, I want to float it in three equal parts. I think I saw the algorithm, but I can’t remember. Any help would be appreciated!
ex) o is debuff image, ’ is middle
one debuff → _ _ o _ _
What you’re looking for is sort of like a midpoint. If you have a line: A--------B (B - A) / 2 gives you the midpoint. Generalizing this to your situation:
var x_end_point = 100
var x_start_point = 0
var debuff_x_positions = []
for i in range(1, num_buffs):
var pos = null
if num_buffs % 2 == 1:
pos = i * (x_end_point - x_start_point) / (num_buffs + 1)
elif num_buffs == 2:
i = 2 * (i/2) + 1
pos = i * (x_end_point - x_start_point) / (num_buffs + 1)
elif i != (num_buffs / 2) + 1:
pos = i * (x_end_point - x_start_point) / (num_buffs + 1)
if pos:
debuff_x_positions.append(pos)
Thank you! I will use physics_process(delta) to load positions at every delta.