Using PlayMaker to create a game, and exporting it to STYLY -3-

The goal for this article series is to use PlayMaker in Unity to create a FPS shooting game, and export it to the STYLY editor.

There are 7 articles for this series, so if you roughly look through the series first, I think you will get the general flow of the tutorial. In this article, we will learn how to add bullet settings to the gun controller.

[6] How to setup bullets

Create a empty Game Object in the Scene Hierarchy, and name it “Bullet”.
As we did with the RainbowCrossbow, we will create a prefab visually using the Scene Editor, and adjust the appropriate controller FSM and insert the prefab into it.

Find the “TeddyGrenade” asset in the FPL_ISBIT > Weapons Pack > 3D folder, drag and drop it to the bullet object, and make it a child of it. It shook be shown in the Scene Editor as the image below.

BulletFinished is created for this tutorial, so keep that in mind. In your Scene Hierarchy, playmakerGameFinished should not exist.

When the bear is out of center, find the Transform component in the Inspector window, click the gear icon, and choose reset. Next, choose a bullet, select Add Component in the inspector window, and search for Capsule Collider. Click it and add it to the bullet.

Edit the collider so it roughly encapsulates the bear. Click Edit Collider to activate click and drag editing, or manipulate the collider by changing it’s radius and height values.

Add a Rigidbody to the bullet, so that physic rules are applied to it. Make sure Use Gravity is checked, so that the bullet gradually drops down as it flies.

Next, we will add a collider to the TeddyGrenade too, but make it slightly larger than the one we set to the bullet. This is since we want to use it as a trigger for certain actions when the collider hits an enemy, and the trigger also stops the asset to collide with other objects such as the ground.

This means that we need a collider larger than the actual collider for the bullet so it creates a trigger range, which can overlap with enemy model trigger ranges. The collider for the bullet has to match the size of the bullet, and should not be set to bounce off enemies and the ground.

Check “Is trigger” on the TeddyGrenade collider, to enable it as a trigger.

Select the bullet game object, and create a state named Moving Forward.

The red square logo located on the right of the assets in the Scene Hierarchy means that a FSM is connected to those assets.

Create a AddForce action in the Moving Forward state, and set 4000 for the Z direction force. Leave the other directions as default. By setting so, the bullets will get shot directly from the gun.

We want the bullet direction to be set according to the crossbow’s angle, not the Z angle of the world, so set Space to Self so that the Z angle of the crossbow will be used.

Then, add an event called “die” and add a transition to the Moving Forward state. Add a Wait action, set it to 20 seconds, set the finish event to “die”, and check Real Time. The bullet will now enter the die state 20 seconds after emerging. This is very important since without this setting, the game will get full with bullets, and start to lag.

To destroy the bullet smoothly, create a state called “Dying”, and add a transition to it from the “die” state. Then, add a “Destroy Self” action to Dying. This action deletes the bullets completely from the scene. Do not check the Detach Children action, since we want to delete the TeddyGrenade asset with the bullet.

Drag and drop the completed bullet Game Object into myPrefabs folder, and create a Prefab.

Return to the Spawning Bullet state in the FSM of the gunController_R game object, and set the bullet prefab you just created to the Create Object action. There will be a red notification mark on the state, so it should be relatively easy to find.

Since we do not need to edit it any further in the Unity Scene Editor, lets delete the original game object now.

That’s it for the settings of bullets. In the next article, we will set up the enemy counter and spawned.

[Related Articles]

Using PlayMaker to create a game, and exporting it to STYLY -1-

Using PlayMaker to create a game, and exporting it to STYLY -3-

Using PlayMaker to create a game, and exporting it to STYLY -4-

Using PlayMaker to create a game, and exporting it to STYLY -5-

Using PlayMaker to create a game, and exporting it to STYLY -6-

Using PlayMaker to create a game, and exporting it to STYLY -7-