Friday, November 29, 2024

Micro Tutorial: Hide and Lock Mouse

 

 
    Quick but very important tip to anyone who is making a first person game, or driving game, or really almost anything aside from management. It's very important to hide and lock your mouse at the start of the game play scene. Locking it keeps the mouse stuck in the center of the screen to keep the player from clicking out if they're playing in windowed mode, and keeping the mouse invisible stops your game from feeling like a middle school presentation.
     

    Though keep in mind if you have any in game menus like a pause menu, you'll have to remember to give the players control of their mouse again. Especially if you're working with a first person game, it can also be a good idea to take advantage of the time scaling again when the player is in menu to stop them from flailing their character around while trying to navigate your UI. It's easier (Lazier, but not a bad thing) than unpairing your mouse from your character controller every time they need to access the menu.
    
     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.


 

 

Thursday, November 28, 2024

Micro Tutorial: Time Control


         This is a small script that I have in my games mostly to make it easier to catch screenshots and cinematics for advertising. It's very simple and incredibly useful. Time moving as normal is at a scale of 1, anything less is slower and anything higher is faster. I've tied the time controls to the Q and E keys using On Keyboard Input blocks to make it easier to capturing during actual play.

    Notice how the Action part of the Input block is set to Down. This means that the block will fire once the key is depressed. If I wanted a little less control and a little more ease of use, I could have had the second block also set to the Q key and the Action set as Up. This would have slowed down time when Q was pressed and the sped it right back up if I let go of the key. 

    I separated the keys so I could stop and make screenshots while in slow motion, but you could easily keep it on one key if you wanted to do something like slow down time when the player aims down their sights. You could even tie it to the same key as aim without any issues. It's a great block, and people should abuse it to recreate 2000s movie choreography. 

    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.


 

 

 

 

Wednesday, November 27, 2024

Micro Tutorial: Increasing size with Loops

 

    Another quick one. This script was built to control and explosion in Nuclear Lizard Island Rampage. Once it spawns into the scene, it grows bigger and bigger before disappearing. I thought it would be a great place to highlight Loop blocks.

    So, you can see this script just has a Start block and not an update block. We could have also used and Update block paired with a Cooldown block set to 0.05 seconds, but this is a little cleaner. The Start block goes to the For Loop (an important distinction since there are other Loop blocks) and the block is set to loop 5 times as you can see in the Last slot. This means that the block will fire whatever you have hooked up to the Body output five times before it fires whatever you have hooked up to the Exit output.

    In this case, our Body output is tied to a script that increases the size of the object. Note there is a Wait block in between the Loop and Scale blocks. If you don't delay the script, it will effectively fire all of the Body loops all at once, leaving no time for human perception. I wanted the player to register the explosion as getting bigger even if it is very fast, which is why there is the 0.05 second delay between scaling up.

    Each time this fires, the script will get the dimensions of the object (Get Local Scale) and add 0.3 in scale to each axis. Note that this Add block is specifically an Vector 3 Add block. A generic Add block will not work. The output of this addition is loaded into the Set Local Scale block and the explosion gets a little bit bigger. 

    After it loops five times, it will go to the Exit output from the Loop block and the explosion will despawn itself. So, it shows up in the world with a scale of 1-1-1, then quickly grows to 2.5-2.5-2.5, then 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.
 


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.
 


Monday, November 25, 2024

Tutorial: How Destruction works in Nuclear Lizard Island Rampage

    I've been using Unity Visual Script (previously Bolt) for around five years now, and I'm still constantly at a loss while trying to find tutorials. So, I thought I would show off some of the (most likely wrong) ways I've done things while building my games with VS and hopefully you all can figure out something better through this. Today, I'm going to take you through how I made breakable buildings in Nuclear Lizard Island Rampage.

 

    We're going to go through the script that makes the common house smashable, starting with getting smacked.

 

     The house has a regular mesh collider to make sure things don't just bounce through it, but it also has a mesh collider toggled to be a trigger. I made this a little bit sloppy, and each different thing that can cause damage to a building has a different tag, which leads to a branch list like the one on the left in the above picture.
 

    Each branch checks for a different tag, like the Attack tag that is attached to the lizards arm. So, if the lizard takes a swing at the house and makes contact with the damage trigger, this fires.


    After it checks the tag, there is a cool down block in the flow to keep the script from firing multiple times per strike. If that isn't there, each punch could count as multiple collisions and take the health of the building lower than I'd like, but with it there, the house can't take slap damage for another 0.5 seconds. 
    After the cool down is a little audio clip so the player can hear that they hit the building. You could also do this with an Audio Source attached to the building, but I wanted to quickly slap this script on a lot of things and not take the time hooking up extra things to their prefabs. After that, we set the buildings health after the strike by getting the current health (an object specific variable integer) and subtracting the force of the lizards punch. This one is a Saved Variable because the player can upgrade their lizard and make the punch force stronger, but for something like explosion damage, it can just be a flat integer. 


    Collecting the input from all the separate ways a building can take damage, we come to the Death Check. If the builds health is not lower than zero, we branch down and temperamentally set the Renderer Material to a material I made called Damage, which is just a bright, blank white. Then it sets it back to the buildings regular material after 0.1 seconds. Effectively, the building will flash white when struck, giving a nice bit of visual feedback.
    Again, I didn't want to be hooking up a lot each time I attached this to a new building. So, on the right side of this image you can see another part of the script that fires once the prefab is loaded into the scene. It creates a new Object Variable called Texture, grabs the regular material attached to the prefab building, and that's what the script will reference at the end of the white flash to get the house looking back to normal.
    If the building health is 0 or lower, then we move on through that cool down seen on the left. Again, using the cool down to this script can't fire multiple times. I don't want it to spawn multiple ruins.
    

     Next, I Instantiate a broken copy of the house (saved as an object variable called Broke) exactly where the current copy of the house is, grabbing the position and location so I can place these all around the scene and the ruin will always show up in the right place. There is also an Empty object stored as an object variable called Civi_Spawn attached to the house right in front of the door, and when the building breaks it spawns a little person (Variable Civ) to run away from the ruin.
 

     Since there is a brief collision between the parts of the broken house with Ridgidbodies and the existing house, the ruins often "blow up" when they're spawned in, which I like. So, I left it. If I wanted to avoid this, I could have created a partent prefab that controls both the house and broken house instead of attaching everything directly to the house. Again, more work. 


    Next there is a little area where we raise the players score, which is saved a Scene Variable because I wanted it to be accessed by multiple scripts in the scene, but I wanted it to get wiped at the end of each round. Each building has is own score saved as an integer as the Building_Score that gets added to the main score upon destruction.
    After that, on the right hand side, there is a Custom Event block that sends the message "Points Added" to an object in the scene that I call the Dungeon Master. This is an object that holds at lot of different scripts and controls a lot of things. When it recieves the message "PointsAdded" it will update the points section of the UI to reflect the variable Current_Score so the player can see that they've got points for smashing up the house.


   Then there is a very brief delay to make sure everything else in the script has had a chance to fire, all the messages got sent, audio played, etc, and then the house is destroyed. Since the Destruction script is attached to the house, this means that nothing in the script will function anymore after this block has fired, but it shouldn't have to. At this point, the house should have taken damaged, given some visual and audio feedback, raised the players score, and then replaced itself with a wrecked copy. If you want to see it in action, check out the Nuclear Lizard Island Rampage trailer.
    
    Anyway, thanks for reading. If you liked this and want more remember, I work on tips. Maybe buy the game or just throw me something on Ko-Fi and I can justify making some more Visual Script write ups. 
 


Thursday, November 14, 2024

Test Post, Please Ignore

Edited: 3/08/25

I'm getting the itch to work on Nuclear Lizard Island Rampage again, but I have bigger plans than the original can support. I think I'm going to start working on a sequel after Tire Fire Rally is finished.