Having issues with Area2D

Darklight1xDarklight1x Posts: 15Member

My issue is that I'm trying to animate a beam with an area2d at the end of it so it can delete an icon, but the icon script isn't detecting the beam area2d.
Icon script:

extends Area2D

func _on_Box1_area_entered(area):
    print(area.get_name())
    if area.get_name() == "Beam Collision":
        if $Box1C.is_disabled() == false:
            $Sprite2.queue_free()
            $Box1C.set_disabled(true)


Comments

  • MegalomaniakMegalomaniak Posts: 1,627Admin

    Do you have any collision detection set up?

  • Darklight1xDarklight1x Posts: 15Member
    edited August 15
    func _on_Box1_area_entered(area):
        print(area.get_name())
        if area.get_name() == "Beam Collision":
            if $Box1C.is_disabled() == false:
                $Sprite2.queue_free()
                $Box1C.set_disabled(true)
    

    This code is my collision detection. So any time another Area2D enter the icon it should be detected. I have the beam AnimationPlayer set so the CollisionShape2D is disabled till it reach the beam end in which CollisionShape2D is enabled ( duration is half a second) then disabled again to finish off the animation. My CollisionShape2D is a child of "Beam Collision" which is a Area2D parent.

  • Darklight1xDarklight1x Posts: 15Member

    Animation being played

  • MegalomaniakMegalomaniak Posts: 1,627Admin

    I was hoping that someone with more 2D experience would comment here, but I suppose there's no fish biting so-to-speak. I'll try to create a small test scene to explore this, but it will take some time. Unless you can supply a minimal test case?

  • MegalomaniakMegalomaniak Posts: 1,627Admin
    edited August 15

    So, from what i can tell, your issue is likely that the node pivot/center is not entering the collision area. Likely since you are animating the node scale and it is scaling from the pivot. instead you want your collision area of the beam to move along with the tip of the AnimatedSprite(?) so that it can enter the other area.

    The actual signal and script work though, here's proof in the form of a really simple example project:
    https://drive.google.com/file/d/1ti_PSJ_n7lSkqUiJhe3zgEe-r9GqSH3y/view?usp=sharing

    edit: TL;DR: Animate the collision areas position or move it from script.

  • TwistedTwiglegTwistedTwigleg Posts: 1,677Admin

    Does the Godot logo sprite/object have a collision shape?
    Looking at the GIF in the initial post, I think I can see a small collision sphere at the beginning of the beam, but I don't see a collision shape around the Godot logo.
    It could be that the Godot logo is drawing on top of the collision shape, like what is happening with the collision shape at the end of the beam, but the Godot sprite will need to have a CollisionShape and an Area2D node to be detected by the beam Area node.

    One thing that could be causing the issue is that the Area suddenly just appears inside the other area, which theoretically could mean the Area does not detect the other.
    However, moving the position of the collision area(s) like @Megalomaniak suggested above should also fix that issue.

    Unfortunately, I don't have much experience with the 2D side of Godot, so outside of that and what @Megalomaniak has already suggested, I'm not really sure.

  • Darklight1xDarklight1x Posts: 15Member
    edited August 15

    @TwistedTwigleg said:
    Does the Godot logo sprite/object have a collision shape?
    Looking at the GIF in the initial post, I think I can see a small collision sphere at the beginning of the beam, but I don't see a collision shape around the Godot logo.

    The Godot logo does have collisionshape as shown here.

    @Megalomaniak said:
    Likely since you are animating the node scale and it is scaling from the pivot. instead you want your collision area of the beam to move along with the tip of the AnimatedSprite(?) so that it can enter the other area.

    Collision Mask moving with the beam

    Result:
    The collision detection is only detected after the animation is finished. I wish for it to be detected during the animation. I also try it with the icon over the collisionshape2d but to no avail it still resulted the same as being not detected.

    I will see if I can fix it by looking at the project files you suggested @Megalomaniak .

  • Darklight1xDarklight1x Posts: 15Member

    @Megalomaniak Similar to the project you posted to download, I already have did have player collision as shown here. Just that I'm trying to implement it with a beam

  • MegalomaniakMegalomaniak Posts: 1,627Admin

    That's kinda missing the point though. I just simplified it down to the basics, is all. ;)

    Now that you know it's not that code snippet you can move on to debug the rest of your scene to figure out whats not working.

  • Darklight1xDarklight1x Posts: 15Member

    I only notice through debugging that it won't detect till after the animation is finished. If there is a possible way for it it to detect midway with the animation that be great.

  • Darklight1xDarklight1x Posts: 15Member

    @Megalomaniak If you wish, I can release the project files here and have you download it to see if you can resolve the issue I'm having. I been stuck on this issue for the past 24 hours. :angry:

  • MegalomaniakMegalomaniak Posts: 1,627Admin
    edited August 15

    If you are willing to share it, I'm sure theres others that might be willing t take a look too, but if noone else gets around to it I'll try to make sure I have some time to look at it tomorrow, it's already late here.

    edit:

    @Darklight1x said:
    I only notice through debugging that it won't detect till after the animation is finished. If there is a possible way for it it to detect midway with the animation that be great.

    In my test project there's a commented out signal(logic-unfilled though), you could try using that instead. It should be a bit more capable than the basic one you were trying to use. Might be a solution right there.

  • Darklight1xDarklight1x Posts: 15Member

    I'm still an amateur in using Godot so please excuse the messiness of my project as I am trying to figure things one by one.
    Download project

  • TwistedTwiglegTwistedTwigleg Posts: 1,677Admin

    While I have no idea if I'll be able to figure out what the issue is, I downloaded the project and will try to take a look and see if I can figure out what the issue is soon, if not tonight than tomorrow.

  • TwistedTwiglegTwistedTwigleg Posts: 1,677Admin

    I found the issue! It seems the issue is there is some strange delay when checking area nodes against each other. This leads to the collisions between the beams and the Godot logo objects to be missed, or only detected when the beam is no longer moving.

    To get around this, I changed the Beam Collision node to a RigidBody with the mode set to Kinematic so it does not move on its own, I changed the collision layer to the second so the player is not effected, I changed the code in the Godot Logo objects to look for physics bodies, and for all of the Godot logo objects, I included the second collision layer so it will detect the RigidBody nodes.

    Some other minor changes/notes:

    • On the Playercollision node, you have the area_entered function connected to a function called _on_Area2D_area_entered in the Player node. However, the script attached to the Player node does not have a function called _on_Area2D_area_entered, which leads to errors in the debugger.

      • To fix this, just disconnect the signal or implement the on_Area2D_area_entered function in the script attached to the Player node.
    • In the Beam_Animation AnimationPlayer, I noticed you are setting the texture(s) for each of the beams to make them visible and invisible. Not knowing this, I played the animation in the editor, and that assigned all of the textures for all of those nodes, making them visible at all times.

      • I redid the animation, instead changing the Visible property of the beam sprites to make them disappear/appear. This way you can play the animation in the editor without having it mess anything up while the game is running.
    • I added movement to each of the collision shapes for each direction. The download included movement only for the east facing beam

      • I also made the collision shapes enable/disable correctly based on the position in the animation
    • Changed the code for the Godot logo objects to disable the collision shape using a deferred call, as the debugger was complaining about it.

    Overall, it appears the issue was just a strange case of Godot not being quite as snappy with Area to Area collisions. This is probably a bug that should be reported at some point.

    Here is a link to the edited project on Google Drive.
    Hopefully it helps :smile:

  • Darklight1xDarklight1x Posts: 15Member

    @TwistedTwigleg Awesome! You totally solve the issue I was having for the past hours. The changes you made also taught me more things about the Godot engine. Thank you so much for helping me out :) . @Megalomaniak And thank you too for trying to help out B).

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file