Watchtowers - Predictive Targeting
/The soon to be latest addition to Fracture the Flag will be the defensive watchtowers. The towers will provide stationary ranged defensive. Something that is very much missing with the current build.
The watchtower script estimates a time of flight, gets velocity of the target, and uses a healthy dose of high school physics to predict the location of the target when the arrow will arrive. There is some inherent error in the calculations as a few assumptions must be made, but these turn out to be minor.
Once the predicted position has been calculated another healthy dose of kinematics is used to create a launch vector for the arrows. This is then turned in to a velocity vector and passed off to the arrow's controlling rigidbody to provide a physically accurate trajectory.
There are some errors in the calculations, such as the time of flight shouldn't be independent of the angle, but one value needs to be calculated before the other... The result can be small errors. The coding also allows a degree of inaccuracy to be added (not shown) for the sake of realism. This quickly makes any numerical errors pretty irrelevant.