Saturday, December 28, 2024

Top Down Tank Tutorial: Firing

 

    Now for a very important bit if you're making a tank, firing.


    Firing, as you might have guessed, is tied to the left mouse click, which according to Unity is Mouse 0. Right after the On Keyboard Input block, we're going to a Cooldown set to 0.5 seconds. So, the player can only fire a shell every 0.5 seconds at the most. In other games, I've implemented an ammo counter and I would also have a check after the cool down to see if ammo is greater than zero, but this is a nice simple tank game. Just a cooldown for this one.


     The Get Variable block is here to orient the shell. The tank has an invisible little object attached to the barrel of the tank just beyond the box collider so the shell doesn't collide with the tank and explode right at spawn. This spot is the BulletPoint. We've attached the Variable Block to a Get Forward block so the shell knows which and then multiplying the forward force by 3 all across the board. So, Get Forward multiplied by a Vector 3 with all slots set to "3."


    Now we're finally spawning our shell into the world with an Instantiate block. The Original slot is tied to a prefab of the tank shell. You can see a Get Position and Get Rotation block on the left side feeding into the Instantiate block. Those two are tied back to the Get Variable: BulletPoint block from the last slide. So, the shell spawns in at the Bullet Point and facing the right direction, which is away from the tank.

    Then we finally move onto the Add Force block to get this shell moving. The little green line between the Instantiate and Add Force is hooked up the denote the force is being applied to the rigidbody of the newly created object. (Note: Your ammo will need a rigidbody if you want this to work. Play with the mass. It can be fun) The force Mode is set to Impulse because I wanted this to mimic a firing round and lose momentum after a bit, and the Force input comes from the Multiply block in the last slide.

    So all the blue square was us figuring out what direction to push and how hard to push it, and then we dump all that information into the Add Force block to actually execute it.


    Also I have this bit because I wanted the tank to make noise when it fires. The position is also set to the BulletPoint. And just below this is a zoom shot of everything so you can reference how it all hangs together.

     That's it for now. Come back soon to learn more about how this tank works. Maybe throw me something on Ko-Fi and I can justify making some more Visual Script write ups, or buy a game. I have a lot of other half-baked scripts to share.

 

 

Monday, December 23, 2024

Top Down Tank Tutorial: Camera Controls

 

    Second bit of the tank tutorial, let's talk very quickly about how the camera is controlled. So, first of all, the camera isn't free floating or attached to the tank. It's instead attached to an empty object that follows the tank around, which let's me also detach it and move it around to see points on interest. 

    The empty object has this little bit of script that keeps it over the player when it isn't going after a point of interest. Every frame (On Update Block) the script grabs the position of the player (in this case called Player_Head) and sets its own position to match. Pretty simple.

    Then we have rotation controls. Anyone who read the last post will recognize these as copies of the rotation controls from the tank, but linked to the Q and E keys instead. Again, using rotation based on the self in the Rotation block. 

    I know this tutorial was a bit short, but the camera controls aren't all that complex, and do they really need to be?

     That's it for now. Come back soon to lean more about how this tank works. Maybe 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, December 18, 2024

Top-Down Tank Tutorial: Movement

 

    I made a simple little top down tank a while ago, and some parts were hard, some were easy. I thought I would share how I threw it together. So, first thing is first. We're going to talk about how the player gets the tank to move around the map.

 
    The controls for this tank are split into two main parts, basically turn and move. This chunk of script is built to rotate the body of the tank. We'll start with the top bit first. On Keyboard Input set to Hold, meaning the script will fire continuously while the A key is being held down. That's linked to a Cooldown block set to 0.02 seconds. I didn't want the tank to spin around too fast, and the Cooldown is there to regulate that. After that, we can see a Rotate block set to self and rotating -1 on the X axis, meaning the tank will turn left relative to itself.
    The second line on this chunk, coded to the D key with a positive 1 on the X axis, is obviously meant to turn the tank right.

    This bit moves the tank forward (relative to itself, not the world or camera). Again, we're using the On Keyboard with a Hold setting, linked to W for forward. Again, a Cooldown block so this isn't firing every frame, and then we are going to a Set Velocity block to move the tank forward. (Note that the tank needs to have a collider and a rigid body for this method to work.) 

    Down on the lower portion, we have a Get Forward block attached to This, so the script can figure out where the front of the tank is. That's fed into a Multiply block and pulling the tank speed from Object variables (which is set to 5 for this tank) and then fed to the Set Velocity block. So, the tank is given a continuous velocity of 5 in the "forward" direction as long as the player holds W.

    The Back portion of the script is virtually the same as the Forward chunk, except you can see the tank speed is multiplied by -1 before it is fed into the whole velocity thing. So, the tanks speed is set in the negative and the direction is reversed. Giving it a second look, I wish I had set the Cooldown slightly longer to make the tank reverse slower than it moves forward, but that's just a little personal preference. 

     That's it for now. Come back soon to lean more about how this tank works. Maybe 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, December 10, 2024

Micro Tutorial: Changing the Player Speed

 

    This is the script I used in Nuclear Lizard Island Rampage to slow down the player when they were stomping around in the ocean. It's relatively simple, one script to set the player to a fixed, lower speed when they get into the ocean (On Trigger Enter) and one to set their speed back to normal when they get out (On Trigger Exit). Both are hooked up to tag checks (which you can read more about here) to make sure the script doesn't trigger when some random things fall in the ocean, only the lizard. I should note that this script it attached to a trigger zone on the ocean itself, and not on the player character even though it controls the player speed. It was easier to do it this way than have checks on the players feet constantly looking out for water.

    You'll notice there are two different speed blocks, one for normal movement speed and one for sprint speed, that need to be set, and those are hooked up to a Scene Object variable through the green lines, which is linked to the player. You'll also notice on the bottom, we're resetting the players normal movement speed from a Saved variable. Since the player can upgrade their movement speed the reset speed need to be able to match their upgrade. We need to make sure we're setting them back to how fast they should be moving and not giving them a debuff when they get out of the water.

    Also on the Set Sprint Speed block, we're taking the players upgraded speed variable (Player_Speed) and running it through and addition block with a fixed variable of 3. I didn't want to mess with another up-gradable variable for sprint speed. So, I locked sprint at always 3 faster than walking speed. 

     That's it for now. 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, December 9, 2024

Micro Tutorial: "Popping" UI

 

    This is a very small thing that I never thing of until I'm in the last rounds of polish with my game, but remember, pop your text whenever anything updates. I threw this script on virtually every piece of the UI in Nuclear Lizard Island Rampage after I brought the game to test and a convention and I kept getting comments like "You should really have [Any Text] as part of the UI" and then I would point out that specific thing as part of the UI that they just weren't looking at. So, change your text color, change the size, maybe have some audio along with it. Let's get into it.

    There are only three blocks in this and they're mostly self-explanatory. We pop the text size to 1.5 with a Set Local Scale and at the same time change it to a vibrant green with Text - Set Color, or if it's a UI element showing the player getting hurt, maybe choose red text. We then Wait for 0.4 seconds and then use the same blocks in reverse to set the text back to the neutral white and the local scale back to 1,1,1. Keep in mind, you will have whatever block starts this script set as a "coroutine" or the Wait block will break your game.

     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, December 4, 2024

Micro Tutorial: Comparing Tags on Trigger

 

    Yesterday(?) I wrote about how the tank turret in one of my games aims at the player, and a big part of getting that to work is letting the tank know that the player is even in range. This is done with triggers and tags.

    The tank itself is surrounded by a huge trigger sphere, but I don't want it firing off every time a crate is thrown through the trigger zone or a civi wanders through. So, after the On Trigger Enter block we go straight to a Compare Tag block hooked up (purple output/input) to an If block. So, if the object entering the trigger zone is tagged as the player, the script will fire and send the message "Liz_Seen" up to the parent object, which in this case it the tank, and that flips a boolean to let the tank know that the player is in range. 

    You can see in this picture there are two almost identical scripts, but note that one is starting with a Trigger Enter block and the other is a Trigger Exit. This way, the tank doesn't need to constantly check if the lizard/player is in range. It just gets notified when the player enters its range and when it exits the tanks range.

     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, December 3, 2024

Tutorial: Controlling a Tank Turret


 

    I like the phrase "Using a sledgehammer to crack walnuts" and this tutorial might just be that, but I'm going to take you through how I got the tank barrel to track the player in Nuclear Lizard Island Rampage, and maybe you can pull a better way out of this. The tank turret is actually made up of three separate independent pieces; the turret (round bit) the barrel (long bit) and the sight (invisible bit). The sight is the simplest and most important part. So, we'll go over that first. 

 


    The sight works off an incredibly simple billboard script. It's only job is to know where the players head is (Get Variable - Player_Head) and face it (Look At - Target) and it does it on an Update schedule, meaning every single frame. This script is slapped on an invisible object with no collider attached to the top of the tank. It's just there to act as a compass for the other bits.

    Side note, the "players head" is an empty object stashed inside the players capsule collider roughly where the head might be. I originally had this script just pointing at the player, but when I did that, everything pointed at the players feet since that was their origin/pivot point and it looked a bit weird.


    

     The tank turret (round bit) is also updating every frame. The first block it hits is an If block hooked up to a large, spherical trigger attached to the tank. If the enemy player is in the trigger area, a boolean gets flipped on and the If block reads as True, moving onto the block where we create a rotation. 

    Pulling from the Sight, which is hooked up as an object specific variable, we get the rotation and from that we pull out just the Y and W rotations. The X and Z have to stay at 0 so the turret only spins around on one axis. Then we move onto the Set Rotation block and feed in our very stripped down rotation data to the Turret, which is also an object specific variable. So, now we have the turret facing in the general direction of the player, but only when the player is in range, and we stopped it from looking up or down.



    The barrel (long bit) works in the exact same way as the tank turret, but we don't strip out any of the rotation data. So, the barrel is free to look the player directly in the eye (or camera) as long as they're in range. The whole effect only works because the turret and barrel are on the same update schedule and were modeled with the exact same pivot point, but it does work, and this whole mess of objects and scripts smoothly rotates to face the player whenever they get into firing distance.

     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.


 

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.