• Register
Post news Report RSS Counter Sniper: Scripting the Smoke Grenade

How the smoke grenade launcher was built with Unity Visual Script for Counter Sniper.

Posted by on

Art13 Faceplate


Like most things in this game, the smoke grenade launcher is slightly hackey.

There are three main parts that all work together; the launcher, the grenade, and the smoke effect.

Art13 Pic1


In this article, we're going to largely ignore the launcher. It is built with the standard "firing" script that you can get a better breakdown of in this article. It's the same as the standard rifle, just with the ammo type, firing speed, magazine capacity, sights, and model swapped out.

Art13 Pic2


So onto the grenade itself. We only need the grenade to go basically where it's fired, fall convincingly, and then stay there as a spawn point for the smoke effect. So the first part of the grenade script.

Art13 Pic3


On collision, this portion of the script gives the grenade a countdown to stop moving. I wanted the grenade to be able to bounce around a bit, but not so much that it would be unusable. So, the grenade gets 2.4 seconds of free time to find a resting place before I freeze the velocity.

Art13 Pic4


Next, I set the rotation of the grenade to zero so when the smoke is instantiated, it is actually facing up. Then there's an “If” check to make sure the smoke stream is not being spawned multiple times. Since this whole thing is being triggered by an if statement, I need to make sure it only gets triggered once. Then I set the local size of the smoke cube.

Art13 Pic5


The Smoke Cube is the hackiest part of this whole mechanism. The enemies need an uninterrupted line of sight to their target to recognize when to shoot. So, to block this view I have a small cube with a clear texture in the middle of the grenade that I expand to act as a shield. It blocks the enemies' view without blocking the players. The cube is also billboarded to the player with the script below so it will always present the player with the broadest protection possible.

Art13 Pic6


Then I spawn the particle system with a built-in count down and self-destruct of its own onto the grenade, and make sure to check the boolean to let the grenade know, as I talked about earlier, not to spawn anymore smoke.

Art13 Pic7


Also, here are the variables for the grenade script.

Art13 Pic8


So, there you go. How to badly script a grenade launcher with Unity Visual Script. If you want vague scripting advice, please give me a follow on IndieDB for updates, join our Discord to tell me how I could do things better, or follow me on Twitter because why not.

And try the latest demo here:

Counter Sniper Alpha 0.04


Post a comment

Your comment will be anonymous unless you join the community. Or sign in with your social account: