Hello Developers!
About a year ago, I started looking through wikipedia, roblox articles, and code segments from other platforms to build a working C-RAM system. I found many articles discussing trajectory prediction, but none of them had the capabilities or the accuracy I was looking for. I’ve made a system that is primarily split into two parts: the creation of the quartic equation, and the solving of it. I tried quite a few methods of my own for solving the quadratic, but I found a great module made by John Kushmer using the Cardano & Ferrari method. I’ve left their credits inside, so props to them! The module is somewhat self explanatory if you have gotten yourself deep enough into scripting to desire using it, but it takes in 8 parameters for the method.
P0: The position of the inital object
V0: The velocity of the inital object
A0: The acceleration consistently applied on the initial object
P1: The position of the target object
V1: The velocity of the target object
A1: The acceleration consistently applied on the target object
Velocity: The exact inital velocity applied to the projectile in order to reach it’s target
Choose Longest: Go with the longer time value over the shorter value
The method then returns the position the target will be at by the time the bullet arrives. These values are intended to be used in tandem with the roblox physics engine, so you can apply a force to your projectile equal to it’s mass times the desired Velocity(keep in mind to also apply any inherited velocity you referenced with V0), or just set the AssemblyLinearVelocity(as I did). I would highly recommend using FastCast, and a client replication system for your projectiles.
You can try it out with a few different turrets in this uncopylocked place: Trajectory Tests - Roblox
I made the little turret demo in about an hour, so don’t expect anything crazy. You can also see a video of me messing around with the system here: https://cdn.glitch.me/f9e80d97-02ff-4c07-b2d6-64aeff5e614a/TurretTests?v=1736140954845
I hope this module can help some of you, so enjoy, and good luck with your development journeys!