I'm trying to reuse assets to save on memory, I previously posted about an issue what has been resolved, that previous issue was being able to assign the collision masking when creating an instance, again that was resolved. My new issue is related to the bullet from the previous posting, I have a variable on the bullet scene called, "bulletDamage." I know how to set the damage in code, when created the bullet instance, but I don't know how to apply the bulletDamage to the player or to the enemy when hit by the bullet instance.
Here's the code I have that doesn't cause any errors, but also doesn't work as desired:
func shoot(): #this is the shoot function from the enemy scene script
var bullet = bulletPath.instance()
var target = $Node2D/BulletDirection.global_position
var direction = Vector2.ZERO
get_parent().add_child(bullet)
bullet.hitBox.set_collision_mask_bit(2, true)
bullet.hitBox.set_collision_mask_bit(3, false)
bullet.position = $Node2D/BulletEmitter.global_position
bullet.rotation_degrees = $Node2D.rotation_degrees
direction = bullet.global_position.direction_to(target).normalized()
bullet.set_direction(direction)
bullet.bulletDamage = 3 #weaponDamage
CoolDown.start()
func _on_HurtBox_area_entered(area): #this is the HurtBox entered function from the player scene script
if hp > 0:
hp -= bulletPath.instance().bulletDamage
else:
state = DYING
It seems to be applying the default bulletDamage of 1 instead of the new value 3 I've given it for testing.