Godot Version
4.0.4
Question
I am making a cooking pot in a game and I need to detect was is put (physically) inside of it. i am using get_bodies_entered() and I don’t know how to make an if statement to detect what has entered
4.0.4
I am making a cooking pot in a game and I need to detect was is put (physically) inside of it. i am using get_bodies_entered() and I don’t know how to make an if statement to detect what has entered
Could you show your code? You could use groups
func _on_body_entered(body) -> void:
if body.is_in_group("Rice"):
pass
if body.is_in_group("Potato"):
pass
body.name is also good:
if body.name == ("turnip"):
You could detect them by groups or by class_name (my preferred method)
class_name Pasta
Create a signal connecting from your Area2D/Area3D to your code.
Select the Area node → Node tab → body_entered(body: Node2D)
It will auto generate a function in your code.
func _on_body_entered(body):
if body is Pasta:
//Do Something
Just be aware the name variable contains the unique name of the node. If you have more than one instance of the object in game, Godot will auto-generate a unique name for that node.
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.