#why is get_overlapping_areas() only running when taken away?
40 messages · Page 1 of 1 (latest)
I would recommend using breakpoints and/or print statements to go through frame-by-frame and see if get_overlapping_areas() is behaving how you expect
On that second shot, the bullet doesn't disappear when the shield does. Maybe the bullet is colliding with the player in the third shot?
get_overlapping_areas() is updated before the physics-step, so there are pretty much 2 frames of movement between when it actually overlaps with other areas and you detect it.
it's suggested to use the entered and exited signals instead if you want an immediate reaction.
I was about to say it's probably better to use the area_entered signal here, yeah
in almost every case i would say
The use of an autoloaded node also seems excessive, but it's not the cause of the issue I don't think
yeah i also don't really understand it, but doesn't really matter for this.
it would also be good to see what the 2 areas that are supposed to collide look like.
get_overlapping_areas returns an Array of areas, have you tried with has_overlapping_areas so it actually returnns a bool?
yeah that should be identical to the function they created.
it could maybe have something to do with the way you're disabling the "shield"?
just disabling an area can be weird since they tend to remember the overlaps. that's why i prefer to disable the shapes instead.
I always struggled with overlapping areas, if you call it every frame it tends to lag behind, i believe takes a phyics_process to process? I only use it in extreme cases and add a 0.1s timer to wait for the areas to get processed.
yeah i've heard also that you aren't supposed to call the overlap methods every frame, that it can get weird for some reason.
For performance reasons (collisions are all processed at the same time) this list is modified once during the physics step, not immediately after objects are moved. Consider using signals instead
from the docs themselves
just use area_entered exited signals
i wanted to have a function that everything could access so i dont have to write the same code over and over. Is there a better way to have that?
This seemed to work for some reason, but is there a way to disable all of the area's children at once?
like i know its just a bool but later i'll have some more complex stuff
Instead of using a singleton global you could make a component scene like "hitbox" and just add the scene into any other scene which uses collision detections.
Also allows you to add custom shapes so you can ahev different shaped areas and the component will take care of all collisions. very handy
is a component just a node with a script?
Basically, can be any node or number of nodes with self contained scripts, you can also add @export variables to add references to other nodes , like if you need a sprite or something else you can just add it in the inspector
ahh okay i get that
You could make a hitbox component which is an area2d with area enter exit signals,etc, then say to any bullet scene you can add the hitbox component and just add a collisionshape
alright sounds cool i think i get it
Cool, just look into composition if you want more info is really helpful if you plan on reusing systems a lot
yea this game i'm planning on making should have a lot of recyclable components with slightly different mechanics
last question i got is if there's a way to disable all the children in a node at once?
yes, but it depends what you mean disabling, often is not neccesary.
maybe for child in node.get_children() to loop throu all child nodes
you can usually hide, queue_free, disable collision shapes etc.
Vortex said that disabling the shape of an area2D works, and it did, but now that means i have to disable everything else that's a child of that area2D
Not all nodes share the same properties, collisionshapes have a disabled property but other node types dont neccesarily do, disabling the collision shape should completly stop the collisions from working
The disable is a property of collisionshape2d not the area2d
No problem, should be easier to manage with components as you can make them do all that themselves 
You could loop through all the children and disable them if they're a shape with if child is CollisionShape2D