Customizable Turret System

Turret System

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. :slight_smile:

Features:

  • Clean and commented script
  • Turret System main script
  • Turret System projectile script
  • Turret System health script, with health bar
  • audio self destruct script
  • constant rotation script
  • load scene script
  • 13 example turrets
  • 3 projectile ammo examples
  • 3 particle examples
  • 9 placeholder sounds

Check bellow for more added features!

2296509--157122--2.PNG
2296509--157123--3.PNG
2296509--157124--6.PNG

Turret System
Version 1.1 Log:

  • Prettier inspector
  • Tool tips. 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 :slight_smile:

Version 1.2 Log:

  • Optimized (added a frequency setting for OnTriggerStay(), making it almost 70% faster)
  • Added DPS for projectile type too
  • Added animation support
  • added ammo, clip ammo, and reload time
  • added turret angle limits for AI too
  • added particle turret

Update v1.3:

  • Pooling (bullets, sparks, muzzle, explosion)
  • Target lead (aim ahead)
  • Visual Particle (bullet casings)
  • Move randomly when no target
  • Fire on button press/hold/release
  • Camera as origin for raycast attack (for FPS)
  • Small fixes and addons

Update v1.4:

  • Min/Max horizontal angle limits
  • Mobile turret option (If checked pools won’t be parented to the turret. Fixes weird rotations of projectiles on mobile turrets)
  • Turret Upgrade (for tower defense games)
  • Turret Upgrade Cost
  • Turret sell value

Update v1.5

  • Third person view. Used in combination with first person view.

Update v1.6

  • Fixed turret not losing track of target once it leaves the range trigger
  • Added an “Auto Fire” feature. Useful for cardboard
  • Optimized scenes
1 Like

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. :slight_smile:

2334264–157710–Turret System Instructions.pdf (675 KB)

All turret examples on display making fireworks. Sorry for no sound. :slight_smile:

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. :slight_smile:

Released! Turret System :slight_smile:

Now working updates for the turrets, and on a complete project asset pack, that will utilize the Turret System.
Here’s the first screenshot in Unity.

I think a demo is needed.

Working on a playable demo (the tanks game above) using the turrets, and video setting up one.

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!
2332331--157520--upload_2015-10-9_18-36-44.png

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.
2332331--157523--upload_2015-10-9_18-43-1.png

I’ll polish and clean up a few more things and upload. Tomorrow I’ll try doing a longer video demo.

looking for a turret system for my mobile game, is this mobile optimized?

I’m not sure, its fresh out of the oven.

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. :slight_smile:

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. :slight_smile:

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 :slight_smile:

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. :slight_smile:

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. :slight_smile:

Latest video.

Updated documentation, now I’ll clean up and upload, and then work on a bit longer demonstration vid before making new updates.

Update 1.1 submitted, and documentation updated.

2334264–157710–Turret System Instructions.pdf (675 KB)

any chance you can upload the apk test you made so i can test it on my mobile?

can the turrets be put on moving vehicles and still rotate / tilt independent of vehicle movement?

can the turrets be fixed upside down to ceilings and sideways on walls?

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. :slight_smile:

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.

2334528--157720--upload_2015-10-11_17-58-10.png

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. :slight_smile:

https://www.youtube.com/watch?v=75W8RKFxhiM

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.
2334528--157724--collage.jpg

Turret System

Video tutorial is out. :slight_smile:

Takes around 2 minutes to set up a turret after watching the tutorial.

Turret System

Working on the next update v1.2.

Done so far:

  1. 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.

  2. Added DPS calculation for projectile turrets too.

  3. Added total ammo, magazine ammo, and reload time. I think you wanted limited ammo @melonhead .

  4. 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.