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. Dismiss Notice

Colliding Visual Problem

Discussion in '2D' started by aLaBaMaK, Apr 25, 2014.

  1. aLaBaMaK

    aLaBaMaK

    Joined:
    Dec 27, 2013
    Posts:
    4
    Hello, I am new to the unity and trying to make a 2D game. I am using the code below for destroying and loading a new scene but when the player collides to an obstacle that kills it especially while falling(which is faster than normal), the player and the obstacle doesnt touch as a visual yet the game starts to change the scene and it looks like the player didn't die to the person who is playing. Any idea why ?

    Code (csharp):
    1.  
    2. void OnTriggerEnter2D(Collider2D other)
    3.     {
    4.         if (other.tag == "Player")
    5.         {
    6.             Application.LoadLevel(0);
    7.             return;
    8.         }
    9.  
    10.         if (other.gameObject.transform.parent)
    11.         {
    12.             Destroy (other.gameObject.transform.parent.gameObject);
    13.         }
    14.         else
    15.         {
    16.             Destroy (other.gameObject);
    17.         }
    18.  
    19.     }
    20.  
     
  2. Kurius

    Kurius

    Joined:
    Sep 29, 2013
    Posts:
    412
  3. aLaBaMaK

    aLaBaMaK

    Joined:
    Dec 27, 2013
    Posts:
    4
    Tried with the timescale but didint help. Still it really differs, sometimes before i hit to the obstacle it changes scene sometimes i collide and go a bit more then changes the scene. The timing is right, player must have hit by that time but the image doesnt show that. Its like the refresh rate is slow so when it collides either the image didint hit yet or almost get past it(sometimes the exact collide occurs). I am playing 70 fps so it should not be the problem maybe but i dont know actually.
     
  4. Kurius

    Kurius

    Joined:
    Sep 29, 2013
    Posts:
    412
    Why don't you purposefully add a delay before the next scene loads. Like have a timer so that the EARLIEST the next scene loads is 2 seconds after player dies. This way you have set a minimum time, and I think it probably doesn't matter if sometimes it takes a bit longer to load the next scene. So really your next scene will load at any point from 2 to 3 seconds after the player dies.
     
  5. aLaBaMaK

    aLaBaMaK

    Joined:
    Dec 27, 2013
    Posts:
    4
    Thank you! Just made a coroutine with 0.01 secs(otherwise character keeps falling:)) and it worked! Wish you a happy weekend :)