#why is get_overlapping_areas() only running when taken away?

40 messages · Page 1 of 1 (latest)

sand sierra
#
#singleton
static func getting_hit(area: Area2D) -> bool:
    var hitting: bool
    if area.get_overlapping_areas():
        hitting = true
    return hitting

#bullet
func _physics_process(delta: float) -> void:
    position.x += speed
    if Singletons.getting_hit(bullet) == true:
        queue_free()```
woven crater
#

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?

lament hinge
woven crater
#

I was about to say it's probably better to use the area_entered signal here, yeah

lament hinge
#

in almost every case i would say

woven crater
#

The use of an autoloaded node also seems excessive, but it's not the cause of the issue I don't think

lament hinge
#

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.

wide terrace
#

get_overlapping_areas returns an Array of areas, have you tried with has_overlapping_areas so it actually returnns a bool?

lament hinge
lament hinge
wide terrace
#

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.

lament hinge
wide terrace
#

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

sand sierra
sand sierra
#

like i know its just a bool but later i'll have some more complex stuff

wide terrace
#

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

sand sierra
#

is a component just a node with a script?

wide terrace
#

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

sand sierra
#

ahh okay i get that

wide terrace
#

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

sand sierra
#

alright sounds cool i think i get it

wide terrace
#

Cool, just look into composition if you want more info is really helpful if you plan on reusing systems a lot

sand sierra
#

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?

wide terrace
#

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.

sand sierra
#

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

wide terrace
#

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

sand sierra
#

yeah i'm aware

#

aight i was just curious, thank you so much for your help though!

wide terrace
#

No problem, should be easier to manage with components as you can make them do all that themselves gdthumbsup

woven crater