Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Destructible Environment Problem?

Discussion in '2D' started by CelticKnight, Nov 3, 2018.

  1. CelticKnight

    CelticKnight

    Joined:
    Jan 12, 2015
    Posts:
    378
    Hi all,

    I am having a problem with destructible environment, I came up with a part solution, but, not fix it completely. Right, I have a bomb that when it blows up (after player touches it) and takes part of the environment away with it. The bomb was just to destroy the environment, but, it destroyed the player as well, not desireable. However, I did want to take energy of the player.

    The code as it does take energy off the player but after the environment blows up the thing is that it puts the player into a perpetual "Jump" state. It won't go back into a walk state at all the control don't function anymore.

    The code I am using is this:

    Code (CSharp):
    1.  Collider2D[] objsDestroy = Physics2D.OverlapCircleAll(transform.position, blastRadius);
    2.         //Collider2D[] objsDestroy = Physics2D.OverlapCircleAll(transform.position, blastRadius, destruct);
    3.  
    4.         foreach (Collider2D blah in objsDestroy)
    5.         {
    6.             if (blah.tag == "Player")
    7.             {
    8.                 blah.GetComponent<Health>().TakeHealth(10);
    9.                 //Destroy(blah.gameObject);
    10.             }
    11.             else
    12.             {
    13.                 Destroy(blah.gameObject);
    14.             }
    15.         }
    16.  
    17.         Destroy(clone.gameObject, .5f);
    18.         Destroy(this.gameObject);

    To anyone who can help here is a big thankyou in advance.
     
  2. CelticKnight

    CelticKnight

    Joined:
    Jan 12, 2015
    Posts:
    378
    EDIT: I figured it out what the problem was, the code as I have it is destroying the groundCheck collider I have on the player controller. Now I have to find a way to keep that back active or stop it from being destroyed.

    I guess making it active again is out of the question because that gameObject has been completely wiped out from the hierarchy, so stopping it from being destroyed is the only option.
     
  3. vakabaka

    vakabaka

    Joined:
    Jul 21, 2014
    Posts:
    1,153
    if (blah.tag == "Player" || blah.tag == "GroundCheck" ||)

    or try: an other raycastlayer for the groundcheck

    or try: different z-position (float minDepth)
     
  4. CelticKnight

    CelticKnight

    Joined:
    Jan 12, 2015
    Posts:
    378
    Doh, of course, I should've realised that!

    Thanks a lot :cool:.