I accidentally created a dodgeball game with projectile motion & movement prediction #Shorts
Published: 22 Aug 2022
I know, I know, it's not #TutorialTuesday and this doesn't even have a full tutorial video (yet!).
I thought this was cool and worth sharing ahead of time though. Most stuff I saw about projectile motion requires you to know a starting point, ending point, max height, and/or initial velocity. This ends up being one too many variables to solve for using our friends in the kinematic equations. You can however use some cool trigonometry and other associated maths to find out that the angle required to throw at is easily calculable from the origin and target position.
So, you can calculate the initial velocity required to throw something at that particular angle. With that part done, you can then find out how long it takes to get to the target given the time it takes for the projectile to reach the current target position and extrapolate the target's position at X time in the future based on your favorite method of guessing - current instantaneous velocity, historical velocity over the last Y seconds, or some other method.
Current instantaneous velocity is relatively straightforward, I took it from the CharacterController.velocity then calculated the force required to hit the player using the same equations above assuming that the player would continue along that direction.
Historical Velocity Projection is a little more cumbersome because we have to track the previous locations over Y seconds and then find out the average velocity (or your other preferred method) and project where the player will be based on that average. The longer duration and more samples you take, the more computationally (and memory) expensive this becomes.
It's a little high level now, but on August 30 I'm releasing a full tutorial about it where I'll explain it in a little more depth, at least to the best of my ability after working through the above references and some trial and error :).
In the meantime, getting hit by these balls is pretty fun.
📱 Let's stay connected
YouTube: https://youtube.com/c/LlamAcademy
Patreon: https://www.patreon.com/llamacademy
Facebook: https://facebook.com/LlamAcademyOfficial
Twitter: https://twitter.com/TheLlamAcademy
TikTok: https://tiktok.com/@LlamAcademy
Instagram: https://instagram.com/LlamAcademy
----
Believe in LlamAcademy's mission and have received value from the videos? Consider becoming a Patreon supporter: https://www.patreon.com/llamacademy
----
Most tutorials come from knowledge gained making https://survival.llama.software Llama Survival - a top-down zombie survival shooter for Android and iOS.
I also have some Unity Assets (affiliate link): https://assetstore.unity.com/publishers/22409?_aid=1101l9QvC