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
  2. Listening to Hit Events

Spawning Particles on Hit

PreviousListening to Hit EventsNextHit Tags

Last updated 4 years ago

Was this helpful?

As mentioned before, RSB works with Object Poolers to manage object spawning. So it's a good idea to stick with the same methodology in our tutorials. Let's create a new empty game object, name it to Default Hit Pooler, then attach the ObjectPooler.cs script on this. By clicking to the prefab selection button next to the Pooled Object field, select the Hit Effect Metal prefab.

Now, let's add a field in our Tutorial.cs script to reference to this pooler.

Then, in our OnAnyHit method, we will get a new pooled object. Place it to the hit position, make it look at to the hit normal, and enable it.

Do not forget to assign the defaultHitPooler variable on inspector of our Tutorial object.

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

Then, if we play and shoot, we will see the default dirt particle is spawned when the bullet hit's the target.

The hit particles have a deactivator script attached to them. So after they are enabled, they disable themselves after a specific time has passed. As soon as they are disabled, they become available to use in the object pool.

Default Hit Pooler object created, Object Pooler assigned, Hit Effect Metal is selected.
Default Hit Pooler assigned
Metal hit particle gets spawned when the target is hit.