Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Keyz312 |
I also need help on alot more things but i need this more at the moment im new to this engine so yeaglh. Actually im new to all engines
Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Keyz312 |
I also need help on alot more things but i need this more at the moment im new to this engine so yeaglh. Actually im new to all engines
Reply From: | Asthmar |
Try something like
if hp == 0:
add_child(potion)
potion.position = position #setting the potions position to the enemy’s position
Queuefree() # freeing enemy
How to add child :https://forum.godotengine.org/36046/how-can-i-instance-by-code
Thanks i really needed it but under which function?
Keyz312 | 2020-05-03 00:21
Your welcome! And put it under the process function because its something you are constantly checking for.
Asthmar | 2020-05-03 00:26
Reply From: | Omar13 |
Im reading the answer and your reply
I think you need to think about “responsibilities” (from the objects)
who get the damage? the enemy
from? The player, the player sword, the player bullet, or whatever
so… lets use Asthmar code and try this
you can resolve this in multiple ways. My approach:
the object that makes the damage (collide with your enemy) will call a func on your enemy
(object wich makes damage)
var damage_amount := 100
_on_body_enterded(body) -> void:
if body.name == "Enemy" #I'm assuming your enemy scene/node have that name
body.receive_damage(damage_amount)
(object enemy)
func receive_damage(damage: int) -> void:
hp -= damage
if hp <= 0:
die()
func die() -> void:
var potion = preload(path_to_potion)
potion.position = position
add_child(potion)
queue.free()
Of course this need a good collision layer/mask and type of node manage