Godot Version
Latest stablerelease
Question
I'm trying to calculate damage accounting for defense and critical strike but the function is always returning 0 and I can't understand why
Here’s the function :
func calculate_damage(damage:int, defense: int, crit_chance: int, crit_multiplier: float) -> int:
print("dmg: "+str(damage)+" defense: "+str(defense)+" crit_multi: "+str(crit_multiplier)+" crit_chance: "+str(crit_chance))
var multiplier: float = 1.0
if crit_chance > 0:
if randi_range(1,100) <= crit_chance:
multiplier = crit_multiplier
print("Critical strike!")
var base_damage = damage*(damage/(damage+defense))
print("base dmg: "+str(base_damage))
var total_damage = base_damage * multiplier
print("total dmg: "+str(total_damage))
print("calculated dmg: "+str(total_damage))
return round(total_damage)
Here’s the output I’m getting in-game :
dmg: 10 defense: 10 crit_multi: 2.0 crit_chance: 0
base dmg: 0
total dmg: 0.0
calculated dmg: 0.0
new hp: 100
I checked through some other prints and the error is in this function but everything seems fine to me so I’m confused.