Projectile.cs - Scripting Reference
Note: "Projectile.cs" has separate manual and scripting reference; other docs combine theirs into one.
Projectile.cs describes the static class Projectile. It is a ready-to-use library containing static methods to accurately solve targeting problems (ballistics), and to predict key projectile data. It also describes our deterministic, math-based trajectory prediction solution.
PEB Trajectory Predictor describes our physics-engine-based trajectory prediction solution, designed to predict in-game behavior exactly.
There are three different ways to do trajectory prediction in total. Refer to the trajectory prediction systems comparison to quickly choose the solution that best fits your project’s needs.
Projectile Aerodynamics describes how to physically add horizontal forces to projectiles while preserving accurate targeting, avoiding the usual trade-off between realism and hit reliability.
Projectile Toolkit 3.1 is available!
Introducing Aero Projectile Launcher, a brand new, easy to use template for projectile aerodynamics feature. (See Projectile Aerodynamics > Template Usage Guide for details).
Announcement: we are evolving this toolkit into a low-code-first, template-driven asset that is immune to LLM disruption. In other words, even if you are using the most cutting-edge AI coding tools, you still need this :)
Next release will be the propulsion update!
Introducing Projectile Aerodynamics, a brand new feature that models aerodynamic forces on projectiles without compromising their ability to hit targets.
You can use this feature to make curved trajectory seen in sports such as football, baseball, golf (draw/fade), etc. You can also use it to model wind, air drag, or implement creative weapons, like boomerangs.
In the upcoming update, some gameplay-focused features will be available:
Getting the information of predicted collisions, including the index, position, rotation and velocity of collisions.
Thanks to the feature mentioned above,
"Collision Count Limit" can restrict the prediction so that it stops when a certain collision count is reached.
You can display the collision points (where the collisions happened).
✅ [Finished] Predicting wind, or draw/fade effects (internally achieved by taking one additional consistent force into account).
✅ [Finished] Simulating projectile movement that is affected by aerodynamics or wind, such as draw/fade effects.
Projectile Toolkit 2.0 is available! Introducing PEB Trajectory Predictor, a brand new system that invokes physics engine to simulate future frames and thus gives accurate prediction.
Version 1.1 coming this week! (Edit: released)
Now you can check out some future features of Projectile Toolkit (work in progress):
PEB Trajectory Predictor: a high-performance, physics-scene-simulated trajectory prediction component.
Propulsion Library/Engine (Drone Example).
The demos are under "WIP" section of the WebGL demo linked in the Unity Asset Store page.
I'm working on Version 1.1:
In this version, I've added two new algorithms and improved several things:
TimeOfFlight(...), which calculates the flight duration of a projectile to hit the target,
ElevationalReach(...), which calculates the maximum range a projectile can reach at a specified launch speed to a specified elevation,
Character Movement Kit: new Forward Vector parameter added, now you can define the character's forward direction. New Rotation Speed parameter added, helps you fine tune the rotation animation of your characters.
The targeting algorithms now get a "/0" check improvement: when start point and end point have the same x and z values, this will cause an error, and now they won't.
I am working hard to bring new features and utilities to Projectile Toolkit. In addition to the new functionalities for targeting and trajectory prediction, one important area I am working on is the propulsion library.
I've realized that there're much more things I can do than just bring you some simple functions that convert between force and velocity, and after some "chaotic" iterations, I successfully implemented the first advanced method of propulsion library.
After that, I was like "why not make a simple drone with the method to test it out? It will behave weird, but it will be very fun". But the result blows my mind, it is PERFECT! I used four propulsion engines, and use AddForceAtPosition(..., ForceMode.Force) to add continuous propulsion to the drone body, and everything just works in harmony, and works like a charm!
See the video showing the result here.