![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | TTG |
I come from a programming background and so I am trying to use Godot mostly through programming.
I wanted to create my own type of node “Boulder” and detect when it collides with my player.
I created the boulder node using only GDScript:
# boulder.gd
class_name Boulder
var area
func _ready():
# Set up the collision for the boulder
area = Area2D.new()
# (omitted) set sollision mask, collision shape, etc
add_child(area)
Then I created my player through the editor.
I added an Area2D node to my player, and used the edtior to connect the area_entered
signal to the player GDscript:
# Player.gd
func _on_Area2D_area_entered(boulder: Boulder):
print("Collided with: ", boulder)
I then have a scene where I spawn a Boulder so that it will fall onto the player.
However, when they collide the boulder
value passed to _on_Area2D_area_entered
is null.
Not sure what is happening here.