Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

OnCollisionStay() weirdness and others

Discussion in 'Scripting' started by raoul, Dec 2, 2007.

  1. raoul

    raoul

    Joined:
    Jul 14, 2007
    Posts:
    6,722
    I have some ball action and code in OnCollisionEnter(), OnCollisionExit() and OnCollisionStay(). All was going well until today. I opened Unity, saw some updating stuff going on, added some code, pressed the play button and hit a ball. When it stopped rolling it should have jumped to the next stroke but it didn´t. I really don´t think I changed anything to these parts before things started to act wrong and I did comment out the code I actually added afterwards.

    The first thing I noticed was that the value of a specific variable declared at the top of the page as:

    var velCount : int;

    stays 0 when I print it from inside OnCollisionStay(). This is actually why the end of the ballflight is not triggered anymore. It did work well before! When I declare the specific variable at the top of the page like this:

    static var velCount : int;

    then it does show the current value in OnCollisionStay(). How is this possible? All works fine in, for example, OnCollisionEnter() when not declaring it as a static variable.
     
  2. raoul

    raoul

    Joined:
    Jul 14, 2007
    Posts:
    6,722
    Another thing to add: print(transform.position); in OnCollisionEnter() returns the original position in scene view not the current position while running the game??

    Did this project get corrupted or something like that or is there an explanation for this?
     
  3. raoul

    raoul

    Joined:
    Jul 14, 2007
    Posts:
    6,722
    Not sure what went wrong here but I took my 1 week old backup, updated scripts and all is working fine again.