Gun Turret
Borne of a desire to see if I could wrangle Unity’s then brand-new ECS library into some dramatic large-scale interactive battle scene I set out to see about building a gun turret.
Issues with parenting game objects to each other within ECS, and with collider coordinates being broken for child objects put a damper on my excitement, but I did end up building a basic understanding of the framework. I also had to wrestle with a lot of tricksy trigonometry, coordinate conversions and PID controller logic to work out how to smoothly rotate the turret within gimbal-constrained axis. So much maths.
In the end I decided to drop the ECS aspect and re-implemented the turret in a more traditional Unity way; I wanted to be able to progress with my game design ideas rather than battle with buggy beta software!
Meet the turret. I'm using this little guy as a context to try learning how to use ECS Job Component Systems :o
— Jez 🌻 (@NinjaJez) September 29, 2019
It's just made out of primitives directly inside the Unity editor, but it's my new fren.#madeWithUnity pic.twitter.com/tTe1yM589p
Turret shoots! Well, it gives it a good go...
— Jez 🌻 (@NinjaJez) September 29, 2019
ECS instanced projectiles working with the new physics library, created inside a JobComponentSystem, with fire rate and clip reload timers also managed within that job.#madeWithUnity pic.twitter.com/rp7jXzj7z2
Round round round round,
— Jez 🌻 (@NinjaJez) September 29, 2019
Gun goes around!
Simple rotation change per update loop, with some cubes to get in the way of the bullets.#madeWithUnity pic.twitter.com/5qX2yfPtQl
Pew Pew!
— Jez 🌻 (@NinjaJez) September 29, 2019
Turns out Mr Turret hates boxes. I'm not very good at the vector maths so it's been a bit of a mission to get a handle on some of the nuances of the limited quaternion support in the new maths lib, but I'm getting there!#madeWithUnity pic.twitter.com/SPn4Fr0fqc
What if... there were MOAR? pic.twitter.com/JjtiyxuLnW
— Jez 🌻 (@NinjaJez) September 29, 2019
This #sideProjectMonday I poked my turret project some more, refactoring the targeting jobs to allow for two teams. I then ran into a wall attempting to parent Entities in #unity3d #ECS - lack of docs is so frustrating! #madeWithUnity pic.twitter.com/Dw1pN3UoCk
— Jez 🌻 (@NinjaJez) October 14, 2019
120 gun salute.
— Jez 🌻 (@NinjaJez) November 21, 2019
Ended up rebuilding my @unity3d turret project without #ECS, as the collider issue appears insurmountable atm.
Don't regret playing with the framework, it shows a lot of potential, but right now I want to actually make a thing that works :3 pic.twitter.com/JfGeJD1meF
Delayed #SideProjectMonday: upgraded my turret script to support multiple barrels :D #moarDakka pic.twitter.com/YkKUcAq0oR
— Jez 🌻 (@NinjaJez) March 11, 2020
Final update for the day: NOW WITH ADDITIONAL TURRETS!
— Jez 🌻 (@NinjaJez) February 22, 2020
Yes, this was secretly Turret Project 2 all along!
Added a little preview ghost, with rotation. Surprisingly involved to create the preview mesh, as the turret is split into multiple gameobjects! pic.twitter.com/cqknRJ8ZL8