Turret System is a customizable script, allowing developers to easily set up their own custom turrets. It can be used in many cases such as shooter games, tower defense games, tank games as the gun of the AI tank, and others that require AI turrets.
Turret customization options range from a few general types such as raycast (instant hit), projectile, homing projectile, laser, shock, and melee, expanding further into detailed customization such as damage, shot range, fire rate, and so on.
Provided in the package are the Turret System scripts, some handy scripts, and over a dozen examples made out of a few placeholder models, and Unity’s primitives. The ones you see on the picture above.
Here’s the pdf documentation, with a simple example tutorial. I tried to comment every line of code, but without cluttering the script or going overboard.
All turret examples on display making fireworks. Sorry for no sound.
The pack is done and waiting approval, but I’m already working on an update, that will allow the player to directly take control of the turret and aim either top-down or from first person. I have plans for the next few updates already, but lets take things slow.
Top-Down and FPS turret controls are implemented. They are no longer just AI. You can take control of the turret with a simple checkbox!
Here’s a short video demo.
Another nifty feature I almost forgot to mention, is the new health bar for the health script. You can see it in the video.
Simply make a world canvas, a prefab of the healthbar image, and drop it into the health script, along with the canvas. Or assign a “World Canvas” tag to the canvas, and the script will find and assign it automatically. You can also adjust the offset accordingly.
I’ll polish and clean up a few more things and upload. Tomorrow I’ll try doing a longer video demo.
If you mean the the top-down and 1st person player controls, then no, I didn’t set up any mobile controls, but I think it should work by default, or with Unity’s standard assets mobile controller script.
As for performance, I’ll do some tests now and see how it performs on my LG Optimus L7 II (which is meant for only 2D games, and weak 3D games), and another better phone.
I tried making it as optimized as possible. Most of the variables, temporary or otherwise, are declared from start. And pretty much all that runs in Update, is checking for a target, a couple quaternions and vectors to calculate the rotation of turrets (head and pivot), and the rotation itself. The rest runs on demand.
Note that the models are only placeholders, they are by all means not optimized for mobile.
PS. Added a nifty new feature that calculates the DPS (damage per second) of the turret, so you can easily balance the power of your turrets within editor. As soon as you change a setting it calculates and shows at the bottom, no need to press anything.
It runs only within editor, so its not an excess weight during runtime. It just takes the damage amount, rate of fire, and number of barrels into consideration. Simple but very useful for balancing. You can also call the function at runtime. I could think of at least one use (EVE Online has a DPS feature on its ships), but I don’t want to make too many updates too fast. I have a lot lined up, and I’m excited about doing them.
Made a menu to switch between scenes so I made a new video too. Just messing around, maxed out everything to see if it’ll still run smooth.
Its locked at 60fps because VSync is on. In Editor its around 70-80fps (but stats as always show over 100fps). I’ll make a mobile build now and see how it runs. But I won’t optimize the models or particles, I’m sure it’ll run fine even on my phone.
Alright done with the update. Plenty new things and improvements.
Version 1.1 Log:
Prettier inspector
Tooltips. Hover over any option and youll get a description of it.
DPS feature (shows damage per second of your turret)
Top-Down player controls
First person player controls
Health bar for the TurretSystem_Health script
Simple handy load scene script for buttons (put it on empty GO or canvas, and drag it into buttons)
Added menu to test out scenes faster
Added 9 sounds
Improvements
Fixes, fixes, fixes
Tested on my low-end phone and the script itself is running fine on 30fps (seems to hit a wall at 30fps like its locked). My phone can’t run most 3D apps I find on the store smoothly, so I’m rather surprised it ran this well.
I didn’t bother optimizing the test scenes for mobile much, I just lowered all settings. The main scene is dying on 2fps (my partner got 10 there) because the scene is not at all optimized for mobile. All the turret placeholders you see are made out of cubes. There’s 600-700 shadow casters in the main scene lol. The other scenes run fine on 26-30fps. The biggest toll is the models I guess.
My partner has a 3 times better phone (not sure the name, its a local brand) but a bit less fps in some scenes, and almost 60 in the tutorial example scene. I guess it depends on the phone too a lot.
I’m not sure that’s a good idea as apk files can easily be “unzipped”. Plus I don’t think my demo scenes are good. The turret examples are just placeholder primitives, each with its own material. Probably most of the lag comes from the unoptimized models, and the standard shader. There’s like at least 10 draw calls per turret.
I’m working on another pack (probably won’t be done any time soon) that uses the Turret System for turrets on tanks, and for the player tank, in a top-down view. I’ll test that too on mobile now.
Yes absolutely. Exactly what it does in the above mentioned game. I’ll record and post here.
Yes. For the AI, the rotation doesn’t matter. For the player turret, I guess sideways would be a problem, because there’s no angle limits on horizontal axis at the moment. Haven’t tested it. But upside down should work.
thanks for the info, i will mostly be using missiles, is there a variable fly speed for these and multiple positioning for turret missiles and are the positions picked at random to fire each missile untill they are all fired.
Missiles use the same script as the projectile script. You just check the “Is Missile” box and it becomes a missile.
Turret System started from a tower defense game, so they have infinite ammo, but limited ammo is on the list to come in the next few updates. If the turret has multiple barrels (muzzle positions), the projectiles are fired from a random muzzle position.
And yes you can tweak the speed, range, and turn speed of the missile. The higher the turn speed the more likely it is to hit the target. Low turn speeds can end up in some hilarious results, with missiles flying around the target, unable to hit it. If the target dodges one fast just before it hits.
And here’s the projectile turrets in action in that tank game I mentioned. Runs the same as other scenes on my phone. Around 26-42fps. Average 30fps. Its a bit better this time because I changed the standard materials to diffuse, and mobile diffuse.
Here’s a few mobile screens I took before they killed me.
Optimized more. Added a check in the OnStayTrigger, to not execute every frame. which seemed to be causing around 10-12ms in the Physics.ProcessReports in the main scene. Now that’s been cut down to around 0-2ms, sometimes 3. Everything else related to the script is less than 1ms total I think. On my mobile its slightly better but it cant pull more than 30-40fps because of the weak gpu. On the PC however it went up to around 200fps. I think the script is super fast, I just wish I had a better phone that doesn’t care about the graphics requirements to test it on, so I know for sure its mobile ready too. Mine is almost strictly 2D games only. But then again what is mobile optimized? What are the standards? Its pretty different depending on the case if you ask me. Thought I’d make a thread and ask about it.
Added DPS calculation for projectile turrets too.
Added total ammo, magazine ammo, and reload time. I think you wanted limited ammo @melonhead .
And finally animation support. This one is still in WIP stage, but almost there.
There’s a few more things I wanna add before I submit this update.