Projectile System
A detailed guide on how to use the projectile system.
Last updated
A detailed guide on how to use the projectile system.
Last updated
While Projectiles (Physical Bullets) can be used, FPS Framework uses Hitscan (Raycast) by default, which are the most common performant method in all first-person shooter games. If you would like to use hitscan you can check this out.
To create a new projectile first create an empty game object and add the component "Projectile" to it. Your game object's inspector should look like this:
This is the default values (Could be different depencing on the current version of FPS Framrwork that you are using.
Hittable layers
The layers which this projectile can detect
Decal direction
The direction of the decal according to the normal value of the raycast
Penetration strength
This amount, which may be referred to as the projectile's "health," is set by the "Default Decal" component and decreases each time the projectile hits an item. The default health damage value is 10 in the event that this component is unavailable.
Speed
The speed of the projectile
Gravity
The gravity multiplier to this projectile. A value of 2 is equal to Physics.gravity * 2
Force
The force the projectile can apply when it hits an object.
Lifetime
The time after which the projectile automatically destroys itself.
Default decal
The default hit impact effect if there's no "Custom Decal" component on the object that got hit.
Destroy on impact
If on the projectile will automatically destroy itself on the first hit.
Use source velocity
If on the projectile will add the force of the shooter to its initial velocity.
Use auto scaling
If on the projectile will scale itself to always look the same to the shooter.
Scale multiplier
The scale of the projectile which the projectile needs to maintain, this is not affected by "Use auto scaling" toggle.
Range
The range of the projectile in which it can deal damage.
Damage range curve
How the damage is affected by its travel distance.
To ignore hits from all projectiles to a certian game object, you can do these
Assgin a layer to that game object and remove it from the hittable layers
Add the component "IgnoreHitDetection" to the game object you want to ignore hits.
This is how your game object's inspector that ignores hits look like:
The projectile can send messages to your custom scripts via a callback function like unity's callbacks e.g OnTriggerEnter(). To add these functions to your script you need to implement the interface "IOnHit" or any of its variants to your script like this:
The function "OnHit()" will be called when the projectile hit any object with this component along with a collider. You can test it by printing a message to the console. The function has a argument of "HitInfo" which contains useful information about your hit.
The hit functions are called from the interface "IOnAnyHit" as well as "IOnHit" and their variants.
You only need to add the "Explosive" component to the same game object that already has the projectile on it in order to change this projectile from being a simple "Bullet" to an explosive one. The rest is explanined in Explosive