0 votes

The areaenter 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 areaenter "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")
in Engine by (12 points)

2 Answers

0 votes

You will probably want to use the body_enter(body) callback instead if it's the projectile object itself you're checking for (providing it's able to collide).

by (138 points)
0 votes
by (14 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.