The game was running at around 90 FPS. But when I modified the bowling pins just like in the lecture, the game has become very laggy. Now when I enter play mode, the frame rate drops to around 3 frames per second and the batches is 99.
I found that the culprit was the convex mesh colliders. But the game was running just fine when the mesh collider was attached to a child object of the bowling pin.
In my opinion, the method that is used to detect if the pin has fallen or not is too heavy since it is being used in the Update event, in my game I’ve used a coroutine with WaitForSeconds method that starts to count after the ball collides with a pin or when it enters the trigger collider to detect if the ball is nearby the pins, and after the chosen amount of time it runs once the method that is responsible for checking if the pin has settled or not, the downside is that the score won’t be updated in real time, but there is a huge boost to performance.
Another option is to control the lag by decreasing the timescale while the ball is inside the trigger collider that checks if it is nearby the pins, you would have to change the update to fixedupdate though, and besides fixing the lag, you will also gain a nice slow motion effect
By the way, you can check what is causing the lag in the Profiler too.
I managed to solve the problem apparently the problem was that I used OnTriggerStay instead of OnTriggerExit. Thanks to this mishap, I learned that it’s not a good idea to CompareTag() inside OnTriggerStay if there are too many objects inside the trigger collider:joy:
Also, to detect if the pin has fallen or not, I simply used a trigger collider and called it “Standing Trigger”. I then had each pin check if it’s inside Standing Trigger, if it’s inside the trigger then it’s standing, if not, then the pin must’ve fallen down
What was the code that you used to achieve this. I cannot for the life of me figure out how to get my pins to appear to be standing up at the beginning of the game.
I created the Standing Trigger allready. I tried to create a bool that would only return true if it received a notification from another method called Void OnTriggerEnterCollider(Collider collider) but the code I was using was displaying all kinds of errors.