Dynamic Scope System

So far, we have learned how to fire a bullet using SniperAndBallisticsSystem.cs instance, listen to the hit events, how to create ricochet-able and penetrable objects using Ballistic Surfaces, and how to incorporate Bullet Time Effects into our scene. Now let's take a look at another powerful tool provided by RSB, Dynamic Scope System.

Dynamic Scope System (DSS) is a Unity Canvas based tool that displays a sniper scope texture, along with how much will the bullet drop, dynamically based on current zoom levels and zero distances. It also has a wind support, displaying where the bullet will land with the current wind settings.

Before incorporating DSS into our scene, let's change it a bit. We had a cube object positioned at 0,0,100 and it had a BulletTimeTarget.cs on it. Let's rename this cube as Bullet Time Cube, then move it to the position 15,0,100. So that it's out of our camera's way. Then let's create a new cube, call it Default Target, then place it to 0,0,200. Also scale this new cube to 3,5,3. Now, we are ready to use DSS.

We can create our own canvas setup, attach the DynamicScopeSystem.cs component on it & setup the necessary variables. However, RSB already provides a completely ready-to-use prefab for this purpose. Navigate to InanEvin>Realistic Sniper and Ballistics>System Prefabs folder and drag & drop the CANVAS - Dynamic Scope System prefab into the scene. Open up the canvas foldout, and select the ScopeReticle object. There you will see the DynamicScopeSystem.cs component.

Head over to the General section, and attach our main camera to Main Camera field. If you play the scene now, there will not be any changes.

DSS has a public method we can call to enable the scope reticle. Open up our Tutorial.cs script and let's write two input checks in our Update to enable & disable the scope.

So, we want to enable the scope when we right-click and hold, then we want to disable it when we release right-click. We don't need a reference to the DSS as it is a singleton object, just like SniperAndBallisticsSystem. We can call the ScopeActivation method in DSS to activate/deactivate the scope reticle.

ScopeActivation method receives a boolean to know whether to activate/deactivate the scope. It also requires a BulletProperties reference, so that it can setup the bullet drop distances & trajectory specific information accordingly. If we play the game now, and click&hold right-click, we will see the scope activated.

By using mouse wheel, you can change zoom levels. Each zoom level is set over the DynamicScopeSystem.cs component.

Each zoom level has a display name, camera's target field of view, as well as sensitivity multiplier. The static float variable DynamicScopeSystem.ScopeSensitivityMultiplier will be set according to the multiplier of the current zoom level. You can use this static variable to change your aim sensitivity during active scope. An example of this is used in PlayerCameraController.cs script, under the folder InanEvin>Realistic Sniper and Ballistics>src>Player.

When you zoom in/our while the scope is active, you will realize that the drop indicator lines at the bottom change. Each line has a distance text next to it. They determine where the bullet will hit (how it will drop) at that specific distance. For instance, if we zoom in really close to our target, hit space bar, you will see that the bullet doesn't hit to the middle of the crosshair, but it hits where the 200 meter drop indicator marks.

This is natural, as the bullet will drop along it's path. DSS is a powerful tool that can show these drops in a 2D manner. It also supports zeroing, so if we change our zero distance, it will dynamically scale the drop distances. Remember we had already written this in Zero Distances section in this tutorial series.

So our whole Tutorial.cs script should look like this:

Now if we play our game, zoom in close to the target, then press C key to cycle the zero distance up, you will see the zero distance changing on the right side of the scope. Set the zero to 200, then fire.

As you can see, now we are hitting exactly where we are aiming at. If we try to hit a target further away from 200 meters, the bullet will still drop, which can be visualized again by the drop indicators below. If we try to hit a target closer than 200 meters, while the zero is set to 200 meters, the bullet will go above where we are aiming at, which is again visualized by the drop indicators.

One other powerful feature of DSS is that it can show the wind effect on the bullet. Right now, our Environment Properties asset does not have any wind speed, so let's change that. Find the Environment Properties asset you have created for this tutorial (you can select the Sniper And Ballistics object in the scene, then find the asset from there since it was referenced). Change the wind speed to 90, 0,0. Now play the game, zoom in, then fire, you will see the bullet will hit to the right side of the target's center. And the orange lines in drop indicators will indicate where the bullet will land according to the wind.

If your wind vector is too powerful, the bullet might land somewhere invisible by the camera (way too far off to the right/left, depending on the wind vector). In those cases, it would be impossible to show where the bullet will land in Screen Space, thus in those scenarios, DSS clamps the position of the orange lines, and displays a "Extreme Wind" text on the screen. This is less of a gameplay feature, but more of a developer tip indicating to you that maybe you have exaggerated the wind vector.

Of course all of this functionality in DSS is completely tweakable over the DynamicScopeSystem.cs component. You can change the line colors, line thickness and maximum widths, along with you can determine what is the maximum drop distance that will be shown, how much gap there will be between the drop indicators, whether to show the wind indicator on top, or whether to show the wind point indicators (orange lines) in the screen. Play with it just to see what can be achieved.

It is suggested to keep a copy of the original prefab in somewhere safe, so your modifications won't change the original DSS preset that comes with the package.

Last updated