Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Corruptinator | |
Old Version | Published before Godot 3 was released. |
Hello! I am currently working on a prototype for a 2D Platformer hack ‘n’ slash type game and I am figuring out how to get the enemy nodes to work…
I wanted to find a way to let the enemies hurt the player if it makes contact/collision with the latter.
I found out that this function: get_collider()
allows the player KinematicBody2D to collect the body of what is colliding/detecting with the other object.
So with that in mind, is there a way to tell by using the array function to see if the player is colliding with an enemy?
I only see through two options but not sure if this works:
I could up an “Enemy” Node2D to store multiple enemies within and then use the function get_children() to get the entire array list of what is within the Node2D object.
The other is the same “Enemy” Node2D but this time it uses get_meta_list()
to work as an alternative array list for the get_collider()
function.
For example:
var enemies = get_node("../Enemies").get_meta_list()
print(get_collider())
for i in enemies:
if (get_collider() == enemies[i]):
#insert Damage Code here
pass
pass
or…
var enemies = get_node("../Enemies").get_children()
print(get_collider())
for i in enemies:
if (get_collider() == enemies[i]):
#insert Damage Code here
pass
pass
Would any of this work so then upon collision it can damage the player?