I Have an issue with my LoseCollider similar to the OP. It appears to be triggering without a reason…
When does this happen?
After you have lost the first ball a new ball appears on the paddle waiting for you to release. If you don’t release but just wait, you will lose your life at a random moment somewhere between 10 and 300 seconds.
What have I done to find the issue?
Log all triggers - On the console all instances where this happens are logged, i.e. a message is logged everytime the LoseCollider is triggered. That’s how I isolated the issue, it is not in the lives calculation or elsewhere. It is caused by ‘firing’ the trigger.
The game can sort of work around the issue by only counting OnTriggerEnter2D when the game has started but the issue still is there:
My Console log:
Ball (Ball)
UnityEngine.Debug:Log(Object)
Paddle:Start() (at Assets/C Scripts/Paddle.cs:18)
Time: 4.92The OnTriggerEnter in LoseCollider.cs is executed with StartStatus = True
UnityEngine.Debug:Log(Object)
LoseCollider:OnTriggerEnter2D(Collider2D) (at Assets/C Scripts/LoseCollider.cs:21)
The player has 2 lives UnityEngine.Debug:Log(Object)
LevelManager:DownTheDrain() (at Assets/C Scripts/LevelManager.cs:38)
LoseCollider:OnTriggerEnter2D(Collider2D) (at Assets/C Scripts/LoseCollider.cs:23)
Time: 4.92The OnTriggerEnter in LoseCollider.cs is executed with StartStatus = False
UnityEngine.Debug:Log(Object)
LoseCollider:OnTriggerEnter2D(Collider2D) (at Assets/C Scripts/LoseCollider.cs:28)
Time: 226.7The OnTriggerEnter in LoseCollider.cs is executed with StartStatus = False
UnityEngine.Debug:Log(Object)
LoseCollider:OnTriggerEnter2D(Collider2D) (at Assets/C Scripts/LoseCollider.cs:28)
Time: 230.04The OnTriggerEnter in LoseCollider.cs is executed with StartStatus = False
UnityEngine.Debug:Log(Object)
LoseCollider:OnTriggerEnter2D(Collider2D) (at Assets/C Scripts/LoseCollider.cs:28)
Time: 233.4The OnTriggerEnter in LoseCollider.cs is executed with StartStatus = False
UnityEngine.Debug:Log(Object)
LoseCollider:OnTriggerEnter2D(Collider2D) (at Assets/C Scripts/LoseCollider.cs:28)
Time: 250.22The OnTriggerEnter in LoseCollider.cs is executed with StartStatus = False
UnityEngine.Debug:Log(Object)
LoseCollider:OnTriggerEnter2D(Collider2D) (at Assets/C Scripts/LoseCollider.cs:28)
Time: 253.56The OnTriggerEnter in LoseCollider.cs is executed with StartStatus = False
UnityEngine.Debug:Log(Object)
LoseCollider:OnTriggerEnter2D(Collider2D) (at Assets/C Scripts/LoseCollider.cs:28)
Time: 256.9The OnTriggerEnter in LoseCollider.cs is executed with StartStatus = False
nityEngine.Debug:Log(Object)
LoseCollider:OnTriggerEnter2D(Collider2D) (at Assets/C Scripts/LoseCollider.cs:28)
Time: 263.64The OnTriggerEnter in LoseCollider.cs is executed with StartStatus = False
UnityEngine.Debug:Log(Object)
LoseCollider:OnTriggerEnter2D(Collider2D) (at Assets/C Scripts/LoseCollider.cs:28)
etc. etc.
Could there be an object out of place triggering the collision?
To see if the paddle or the ball is causing the trigger through some glitch I have logged the location of the paddle and the ball. It appears that they are not entering the Collider2D.
My console Log:
Ball (Ball)
UnityEngine.Debug:Log(Object)
Paddle:Start() (at Assets/C Scripts/Paddle.cs:18)
Time: 4.02The OnTriggerEnter in LoseCollider.cs is executed with StartStatus = True
UnityEngine.Debug:Log(Object)
LoseCollider:OnTriggerEnter2D(Collider2D) (at Assets/C Scripts/LoseCollider.cs:25)
Current Paddle Location = (7.7, 0.2, 0.0)
UnityEngine.Debug:Log(Object)
LoseCollider:OnTriggerEnter2D(Collider2D) (at Assets/C Scripts/LoseCollider.cs:30)
Current Ball Location = (11.0, 0.0, 0.0)
UnityEngine.Debug:Log(Object)
LoseCollider:OnTriggerEnter2D(Collider2D) (at Assets/C Scripts/LoseCollider.cs:34)
The player has 2 lives
UnityEngine.Debug:Log(Object)
LevelManager:DownTheDrain() (at Assets/C Scripts/LevelManager.cs:38)
LoseCollider:OnTriggerEnter2D(Collider2D) (at Assets/C Scripts/LoseCollider.cs:41)
(Note for Gamedev forum: the above is correct. I was playing and dropped the ball)
Time: 83.6The OnTriggerEnter in LoseCollider.cs is executed with StartStatus = False
UnityEngine.Debug:Log(Object)
LoseCollider:OnTriggerEnter2D(Collider2D) (at Assets/C Scripts/LoseCollider.cs:25)
Current Paddle Location = (0.7, 0.2, 0.0)
UnityEngine.Debug:Log(Object)
LoseCollider:OnTriggerEnter2D(Collider2D) (at Assets/C Scripts/LoseCollider.cs:30)
Current Ball Location = (3.4, 0.1, 0.0)
UnityEngine.Debug:Log(Object)
LoseCollider:OnTriggerEnter2D(Collider2D) (at Assets/C Scripts/LoseCollider.cs:34)
(Note for Gamedev forum: I didn’t play just waited for the trigger to happen. At the 83 second mark is triggered. Both Paddle and ball were not missplaced or in the area of the LoseCollider)
I can log a lot more of these but the result is the same. It keeps triggering and never because the ball or paddle hits the collider.
edit: It is also not the smoke because this also occurs when the first ball only strikes the white brick and not the breakables. Oh, did I mention it occurs not with the first ball but after the first it keeps happening.
Where exactly does this go wrong?
To provide a bit of additional context I added a screengrab from my Unity view so you can see the location of the ball, paddle and losecollider.
I din’t post more info on the scripts because A) the OP already did that and B) I am fairly sure this is a problem in Unity and not in the scripts.
However, if more info is required I would gladly provide more.
To summarize: how the hell do we stop LoseCollider Box Collider 2D from triggering without provocation?
Anyone?
@Rob ?