Tuesday, November 26, 2024

Micro Tutorial: Making some Randomized Despawn

 

 
    This one is going to be short and sweet. I built this script to despawn smoke streams from ruins at different times so it would look more natural. It's small, simple, and could be applied to a bunch of different mechanics. So, let's get into it.
    From left to right, I have an Update block linked to a Cooldown block set at 1.4 seconds. At the end of the cool down, it calls a Randomizer block that spits out a number between 1 and 10. The number that spits out, the blue line coming off the right side of the block, is sent to a Rounding block. The Randomizer will spit out numbers with decimals, floats, instead of round numbers, integers, and we don't want that. So we send it to the Rounder to clean it up.
    Then we send it on to an Equal block with a Literal Integer set to 1 in the B position. We're checking the number that the Randomizer spit out (A position) against the 1 Integer (B position) and seeing if they match up. Then we send that data up to the If block using that pink line as the input, and if it is true that A=B, then we go onto the Destroy block and get rid of the parent object.
    To put it very simply, every 1.4 seconds the prefab is rolling a 10 sided die and if it comes up "1" it vanishes.

    Thanks for reading. If you want more maybe buy the game this script came from or just throw me something on Ko-Fi and I can justify making some more Visual Script write ups. I have a lot of other half-baked scripts to share.
 


No comments:

Post a Comment