Hello and welcome to this guide on how to use Varun’s Controllable Turret Weapon Creator Package!
What does this Package do?
This Package allows you to create your own Controllable Mounted/Turret Weapons and define their behaviour in a simple way. It includes Scripts that you can use to customise your Turret Weapon’s Ammo, Damage, Projectile Settings, Rate of Fire, Effects and Sounds, Post Processing and a lot more.
You can find me on the Crayta Discord at Varun#8144 if you have any questions.
I’ll be happy to help
This Package comes with 4+ example Turret Weapons which can be modified to create anything ranging from Cannons, Miniguns, Machine Guns or Railguns!
- Controllable Turret - A Missile Turret you can walk up to, Press E to Activate, WASD to Rotate, LMB to Shoot and Q to Deactivate
- Controllable Turret (Control Panel) - A Missile Turret you can Activate from a Control Panel far away
- Controllable Turret (Wall Camera) - A Wall Mounted Machine Gun you can Activate from a Control Panel far away
- Controllable Turret (With Health) - This is the same as the Wall Camera Example but with Health! You can set Health Points for the Control Panel and the Turret Body, and when either of them is destroyed, the Player controlling the Turret automatically gets disconnected . This particular Example has slightly different instructions explained at the end of this forum post.
Read on to learn how to add these example Turret Weapons to your Game and how to create your own Turret Weapons without writing a single line of code!
Once you’ve installed the Package, you should see this in your Library:
There are 2 ways to do this, pick the one that suits you best:
1) The Do It Yourself Way (I want to learn how to create and customise my own Turrets!)
2) Using the Example Controllable Turret Templates (I just want to add Turrets to my Game ASAP, any Turrets!)
Let’s go over how to Create your own Turret Weapon by yourself and then, once you’ve understood that, the shortcut way to rapidly create Turret Weapons!
The Do It Yourself Way
1. Add the Turret Camera Controller and Local Handler Script Folders to your User Template. You can find them in your Library
2. Create a new Script Folder called Turret Controller in your Player Template and add the turretControllerScript to it
3. Create a Locator for your Turret in the Game World and Template it. Name it whatever you like!
- I’ll name mine MyTurret! Follow along if you like.
- Add another Locator inside the Locator of your Turret. Name it Turret Parent.
- Add a Camera inside the Turret Parent Locator. This is the POV you will be shooting from when you activate the Turret. Name it Turret Camera.
- Add any Mesh or Template as a child of the Camera. Name it Turret Body. This will be the Entity that the Player interacts with to Activate the Turret. You can customise the Turret Body however you like.
- Add another Locator as a child of the Camera. Name it Turret Muzzle. This will be the muzzle of your Turret i.e. the point where your Turret shoots projectiles from.
- Make sure the Camera’s POV is not obstructed by the Turret’s Body or anything else.
Your Turret should now look somewhat like this:
4. Adding Scripts, Setting Properties and Bindings for your Turret
- Add the controllableCameraScript to the Turret Camera
Set the onClient property to false and the other properties to whatever you like (it’s important to do this or else it wouldn’t work). I would recommend setting the horConstraint to 90 and verConstraint to 30.
- Add the controllableTurretScript to the Turret Body
Set the turretMuzzleLocator property to your Turret Muzzle
Set the turretProjectileTemplate to Turret Projectile if you want a Missile, Turret Bullet Projectile if you want a Heavy Bullet. Tip: You can edit both of these Projectile Templates to customise their behaviour!
Set the turretWidget property to TurretUIWidget
You can set the other properties to whatever you like.
Add the TurretUIWidget to the Turret Body. Make sure the Type is Screen and visible is set to false.
Select your Turret Body and create 2 On Interact Bindings by clicking the [+] icon
5. Add your Turret to the Game and set a reference to it in the Player’s Turret Controller
You’re almost finished! You can now place your Turret anywhere you like in the Game! Now, Go to the Player Template and in the Turret Controller, add Turret Body to the array (since it has the controllableTurretScript attached to it!)
That’s it! You’ve just created your first Controllable Turret Weapon without writing a single line of code!
Click Preview/F5 to test it out!
Using the Example Controllable Turret Templates
This step assumes that you have completed Steps 1 and 2 from the DIY Method above. That is, adding the Turret Controller to the Player and the Turret Camera Controller and Local Handler on the User.
Now, you can place any of the 3 Example Controllable Turret Templates in the Game World.
After that, you have to set a reference to their Turret Body/Turret Control Panel in the Turret Controller on the Player. Refer Step 5 above.
That’s it! You’ve just added your first Controllable Turret Weapon without writing a single line of code!
If you don’t like how the Example Turret Templates look, you can go ahead and edit the Templates itself! But, be careful with the Turret Body/Turret Control Panel, since they have Bindings attached to them, and they are what the Player Interacts with to Activate the Turret!
Using the Example Controllable Turret (With Health)
First, follow these steps written above.
- Now, go to the Controllable Turret (With Health) that you have placed in the World.
- Select Turret Control Panel. Scroll to the bottom to the When Health Zero Event Bindings
- Replace the “Entity” part of the Bindings from Player Template (Turret Example) and User Template (Turret Example) to your actual Player and User Templates. The Bindings should now look like this:
- Repeat the same steps to modify the When Health Zero Event Bindings on securityCamera2 and Turret Body so that they look like this:
That’s it! You’ve just added your first Controllable Turret Weapon (With Health) to your Game without writing a single line of code!
Again, if you have any questions, feel free to message me on Discord at Varun#8144
Congratulations on finishing this guide on the Controllable Turret Weapon Creator Package!
I hope you are now ready to create your own Controllable Turret Weapons in Crayta!