#Does Collider2D count it as "area entered" when you enable the area and the objects already there?

1 messages · Page 1 of 1 (latest)

edgy meadow
#

Hi! I have a moving object with two colliders for an explosion spell. One is disabled till the other hits something. The disabled one is bigger than the one that detects hits. It doesn't work and I am suspecting it's because when I enable the hitbox the enemies are already in there.

What the code currently does correctly:

  • Detect when arrow hits enemy
  • Delete arrow
  • Enable the hitbox
  • Disable the hitbox again after x time

What I need it to do that it does not do:

  • Hurt the enemies

If I take out the enable/disable bit the code damages the enemies just fine

flint vault
#

maybe use it once when you "enable" like this..

for body in hitbox.get_overlapping_bodies():
  _on_impact(body)
edgy meadow
#

Oh hey I didn't know this existed, thank you 😄

#

hmm interesting, it does give me a local _body but it never reaches the second breakpoint. Did I implement it wrong?

flint vault
#

uuh .. so you are disabling the collisionshape and after checking if something collides?

#

i'm a bit confused what the goal is tbh

#

no wait, you are enabling it.. my bad

#

you might need to wait for the physics engine to actually do something (calc a frame) before that function would work

#

i would assume..

#

maybe you can just leave the hitbox collision shape enabled and only "query" for intersecting overlapping when you need them, with that function

edgy meadow
#

Thanks! I will try that 🙂

edgy meadow
#

Unfortunately, it still does not work, it does do the area_hit -> physics -> disable though but it still won't trigger what's inside the for loop

flint vault
#

Can you explain why you enable and disable the hitbox? What is the general idea behind it?

edgy meadow
#

The idea behind it is that it's an explosion, and so it should be disabled till it hits and then enabled

#

But honestly the main reason is that I was following this tutorial https://www.youtube.com/watch?v=sWUGxkbh2fg

#

Now that you mention it, I get why it turns on, I don't get why it turns off

#

As in I thought I got it but now that you mention it I can't explain why I thought it was logical

flint vault
#

Don't have much time to fully grasp what going in that video right now.. but i heard him saying here that its very important that "impact and hitbox are the same size" :P ... Dunno if it really matters though https://youtu.be/sWUGxkbh2fg?t=206

edgy meadow
# flint vault Don't have much time to fully grasp what going in that video right now.. but i ...

That was for the first arrow, I think this part is more helpful, it's where he's explaining the change for the arrow https://youtu.be/sWUGxkbh2fg?si=Nr7jrP02nKXgnOvu&t=999

#

I edited it because the first one had the wrong timestamp, sorry

#

but you're right, I commented out the disabled and it did nothing as the object is getting destroyed anyway 🙂

edgy meadow
#

It's fixed!!!

#

It's a bit of a roundabout way but I figured, hey if the scale change is working but the disabled isn't, why don't I just...not disable it, start the radius at the same size as the other collider and then enlarge it when it actually collides

#

and that works 😄

#

Thank you so much for all your help!