Realistic Sniper and Ballistics
  • Welcome
  • Introduction
    • Feature List
    • Why/How is it used?
    • Quick Setup
  • Getting Started
    • Getting Started
    • Environment Properties
    • Bullet Properties
    • Object Poolers
    • Sniper and Ballistics System
    • Firing a Bullet
    • Listening to Hit Events
      • Spawning Particles on Hit
      • Hit Tags
    • Zero Distances
    • Wind Vector
    • Air Resistance
    • Spin Drift
    • Ballistic Surfaces - Penetration
    • Ballistic Surfaces - Ricochet
    • Bullet Time Effects
      • Target
      • Bullet
      • Firing with Bullet Time
      • Bullet Time Camera - Default
      • Writing your Own Bullet Time Camera
    • Dynamic Scope System
    • Incorporating Player
      • Player Movement Controller
      • Motion Controller
      • Camera Controller
      • Player With Weapon
    • Mobile Controls
    • Conclusion
  • API
    • API Welcome
    • Sniper and Ballistics System
    • Dynamic Scope System
    • Player Movement Controller
    • Motion Controller
    • Ballistic Surface
    • Environment Properties
    • Ballistics Utility
    • Bullet Time Utility
Powered by GitBook
On this page

Was this helpful?

  1. Getting Started

Incorporating Player

PreviousDynamic Scope SystemNextPlayer Movement Controller

Last updated 3 years ago

Was this helpful?

So far, the information we have learned should be enough for you to easily start using RSB in your own player controllers & character systems. However, if you don't have your own character system, or if you want to build upon a base, you can use the example first-person controller provided by RSB. Let's change the tutorial scene such that instead of firing from the main camera, we will fire from the player camera.

First, delete the Main Camera object. Then navigate to InanEvin>Realistic Sniper and Ballistics>System Prefabs folder and drag & drop the Player Without Weapon prefab into the scene. Position it to 0,1,0. Then go over our Tutorial object, you will see that the Main Camera is missing. Drag & drop the Main Camera under the player prefab in the hierarchy. Then go to the Sniper and Ballistics object and assign the same Main Camera to the Fire Transform field of the SniperAndBallisticsSystem.cs instance. Next, go over to the ScopeReticle object under CANVAS - Dynamic Scope System where the DynamicScopeSystem.cs component is attached, and assign the same Main Camera under the player to the Main Camera field. Finally, open up our Tutorial.cs script, and modify the if block where we are firing to:

Remember we used to fire using Space key, but that will conflict with the Jump input of the player controller we just dragged in. Now, we have just switched that to the left-click mouse button.

There is only a small thing left to do. The Player without Weapon prefab, as well as the other player prefab we will talk about in the upcoming sessions, are layered as IgnoreRaycast. This is only for the sake of the demo scenes, of course in your own project, you might want to raycast to the player, e.g. from an enemy, so you might want to put the player into some new layer like Player. But for the RSB package, we did not want to mess with your project settings & layers, so we have just put the player under IgnoreRaycast. Now, it is possible that when we fire from the player, the rays might hit any object under the player, if we were to have an object with a collider. That's why we want to bypass the player during our raycasts. Go to the Sniper and Ballistics object, and change the Ray Mask value to Everything but IgnoreRaycast (Mixed).

Since the player is in IgnoreRaycast layer, now the rays casted from our fire transform has no chance of hitting the player collider, or any object we put under the player if there were to be one.

If you play your scene now, you will be able to walk around, and shoot with the mouse left-click. Remember, you can also aim with right-click.

Let's also debug the bullet trajectory in-game. Create a new game object, call it Trajectory Renderer Pooler, attach the ObjectPooler.cs component on it. Then click on the search field of the Pooled Object field and assign the Bullet Trajectory Renderer prefab on it.

Then go over to the Sniper and Ballistics object, enable In-game Debug renderer settings, and assign this pooler to the Trajectory Renderer Pooler field.

Now if you play the game and shoot, you will see the bullet's trajectory being rendered with line renderers.

Let's take a look at the details of the player prefab we have just dragged in, just to understand how it works.

Every layer except IgnoreRaycast is selected.
Shooting with the example player controller.
New object created & ObjectPooler.cs attached, with Bullet Trajectory Renderer set as pooled prefab.
In-game Debug enabled, trajectory renderer pooler assigned.
In-game trajectory rendering.