Search Unity

Resolved Detecting AoE damage with changing timeScale and enabling/disabling collider gameObject

Discussion in 'Physics' started by Braza, Nov 10, 2021.

  1. Braza

    Braza

    Joined:
    Oct 11, 2013
    Posts:
    136
    There's a rocket game object flying towards a surfaced submarine. A rocket has a disabled AoE gamebject with an active collider (kinematic rigidbody). Once a rocket hits the surface it setsActive the explosion child with for 0.1 unscaled seconds and expects to receive OnTriggerEnter for submarine colliders (dynamic rigidbody).
    The game also has tactical pause leveraging timeScale=0. It may happen right after or right before the explosion too.
    I observe sporadic misses of hits. Are there any problems with this approach?
    Can any rigidbody fall asleep if timeScale is 0 for ~30 seconds?
    Should OnTriggerEnter event fire if GameObject gets enabled after colliders overlap?
    upload_2021-11-10_19-11-36.png
    upload_2021-11-10_19-10-2.png
     
  2. Braza

    Braza

    Joined:
    Oct 11, 2013
    Posts:
    136
  3. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,500
    I'm finding it hard to follow your post as there's a lot of redundant info here. No idea what AoE is (should I know?) Also things being children or kinematic kind of make no difference.

    So when time-scale is zero, FixedUpdate is not called because that's the whole point. On the assumption you have 2D physics running as default in the FixedUpdate then no, it cannot fall asleep because the simulation is not running. That's irrelevant because if something overlaps then it'd wake up. 2D physics won't do anything. It's not different than your code not running in the FixedUpdate because it's not called.

    Again, a very odd question; yes, of course physics callbacks happen as they normally do.

    You might want to think about physics as a simple function. If it doesn't run (let's say because you set time-scale to zero) then it doesn't do anything. If you disable a Collider either directly or indirectly because the whole GameObject/Hierarchy is inactive then there is no physics object behind it so even if the physics system is running, there's nothing there. If you enable it, it shouldn't be a surprise and should be expected that there is then a physics object behind it and when the simulation runs, it'll work as expected.

    In summary, you're messing around with time but in the end, physics comes down to the simulation step. If it runs, it does what you expect: create contacts, solve contacts, report contacts. Check if the simulation step is running in your logic.
     
    Braza likes this.
  4. Braza

    Braza

    Joined:
    Oct 11, 2013
    Posts:
    136
    AoE - area of effect. I was pretty sure that this is common knowledge in game dev.
    I do appreciate your extensive response. I provided redundant info specifically because I did not know what would be relevant.
     
  5. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,500
    I know what an area of effect is however I typed "AoE" and "AoE game dev" into Google and nothing came up. Not everyone uses acronyms for everything though.

    Well hopefully it helped too. All the info is good but sometimes it just makes it difficult to understand the actual problem. Acronyms, parent/child relationships, timers etc. It's a bit like going to the doctor and describing your symptoms by detailing what you were buying in the shops at the time you felt the pain. :)

    If you still have a problem then I'm happy to help.