Added: Respawning Blocks


It took me longer than I thought to allow these damn blocks to respawn. The project has gone through many changes for this one, simple addition. Here is a list of what I did first and how it changed:

First, I gave every destructable block a raycast to check if the player is too close to have it respawn. If the player is 4 blocks away in up, down, left and right direction it can respawn. What this didnt consider is A: Players inside the blocks and B: Players around the corner. It was pretty much the same Raycast that Ive done with the explosion.

To fix A, I gave it another check to see if something is inside of it and if yes, not respawn and check again in a few seconds. What this now still didnt consider was players being around the corner. Also, the raycast being for every single destructable gave up a lot of performance. And changing it to check everything around them was much harder and even worse on the performance so I decided to change it.

First, I added a collider to the players like this: 


I still had the Raycasts on the blocks but also added a trigger check for them to see if it hits the collider (the collider is a trigger). But whatever happened, it didnt change anything except for allowing the raycast to find the collider if the destructable is not inside of it (pretty much like the player being inside the box issue). I couldnt use the same method that I used to fixed that error because it checked the location of the player and the box, but since the collider is always at the players position that won't work.

I was stuck. For a pretty good while. But then I found a work around thanks to help from other developers. I have removed the Script & Raycast entirely from all the destructables and wrote a new script for them. They would only do basic stuff and have some bools that say if they are inside the trigger or not.

To find that out, I didnt depend on the boxes anymore but on the triggers: I wrote a new script for the triggers to check if they are touching a box or if they are no longer touching it. They would tell the box and the box could then respawn/stop respawning. Such a simple fix for such a drawn out and really simple problem.

Now I no longer have excessive lag when lots of boxes are broken and the detection is much easier. Thanks a lot, BrahRah.


Now these boxes won't spawn unless they leave the radius of the trigger.


Files

ItchBuild.zip Play in browser
Sep 25, 2019

Leave a comment

Log in with itch.io to leave a comment.