Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Oranjoose | |
Old Version | Published before Godot 3 was released. |
The area_enter callback works when I create an Area2D node inside the scene editor with a child CollisionShape2D, given a RectangleShape2D, and then having the Area2D node’s area_enter “connected” to a custom function. Again, this way works.
However, if I make a subclass which extends Area2D, I cannot get the area_enter callback to work. I try with the default callback, with a custom function, and I try to check overlapping nodes in the process function. Here’s an example of the code:
class Projectile extends Area2D:
var projSprite
var collShape
func _init(x, y):
set_process(true)
projSprite = Sprite.new()
projSprite.set_texture(load("projectile.png"))
add_child(projSprite)
set_pos(Vector2(x, y))
collShape = CollisionShape2D.new()
var rect = RectangleShape2D.new()
rect.set_extents(Vector2(10,10))
collShape.set_shape(rect)
add_child(collShape)
connect("area_enter", self, "projectile_enter_area")
func _process(delta):
translate(Vector2(0, -400 * delta))
if (get_overlapping_areas().size() != 0):
print("somethinggg overlapping")
func _area_enter(area):
print("area collision")
func area_enter(area):
print("area collision")
func projectile_enter_area(area):
print("custom collision callback")