Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Dava | |
Old Version | Published before Godot 3 was released. |
I tried
extends Kinematicbody2D
func _ready():
set_process(true)
func _process(delta):
if(get_collider() == Kinematicbody2D): # I even tried if(get_collider() == "enemy")
print("Ouch!")
queue_free()
And this
#all previous code except for process function
func _process(delta):
if(is_colliding()):
if(get_collider() == Kinematicbody2D):
print("Ouch!")
queue_free()
For Rigidbody2D
I use get_colliding_bodies ( ) and then check if it contains the specific body. But I don’t know about Kinematicbody2D
.
Anutrix | 2017-04-11 08:42
Did you try this:
#all previous code except for process function
func _process(delta):
if(is_colliding()):
if(get_collider() == get_node("enemy")):
print("Ouch!")
queue_free()
where enemy is name of specific node with which current body is colliding.
Anutrix | 2017-04-11 08:45
Yes I tried that but the enemy node is not in the player scene so I wrote this get_tree().get_root().get_node("enemy")
it worked but when the player touches other objects the queue_free()
action runs. So I tried implemeting it at the enemy script since the player will be the one affected I wrote
if(is_colliding() == get_tree().get_root().get_node("player")):
print("Ouch!")
get_tree().get_root().get_node("player").queue_free()
Godot can’t even find the player scene, any ideas on how to fix that
Dava | 2017-04-11 18:23