Hello Everyone! Before we get started, Please make sure you satisfy the following requirements.
- Your browser is compatible with STYLY. You can check that out once you sign in to STYLY.
- Your Machine must have at-least 4gb RAM to ensure fluid content creation.
- Make sure you have installed Unity 5.6.3p1 with the required components.
- You have purchased and installed Playmaker Plugin for Unity.
- You have downloaded the STYLY plugin for uploading scenes created in Unity from here.
This tutorial assumes you have gone through the Unity X Playmaker X STYLY tutorial series. Please go through this before you start this tutorial. Now that that’s out of the way, let’s begin the actual Development. We will develop all the content in Unity and then export it to the STYLY account linked to Unity via the STYLY plugin.
I would like to show you how we can use playmaker to make STYLY scenes intractable. For that purpose, we will be developing a simple ball game. To set up a simple environment, we will need a cricket stadium model freely available on 3dwarehouse. The wickets in this stadium can’t be used for our purpose as its part of the mesh. So, we will delete that part of the mesh in the stadium and create our own wickets using Unity’s own 3d objects.
To make the wickets, simply use 3 vertical cylinders as the stumps and 2 cuboids as the bails. Next, add a rigid body to all parts of the wicket. Make sure to decrease the mass of the bails as otherwise, they might fall through the stumps.
Once your wicket is ready, place it in inside the stadium object in the hierarchy and then move the wickets at the edge of the pitch.
Now that the environment is ready, let’s move towards the fun stuff. We will now replace the VR hand held controller model with a Ball. To do so, first, create a prefab of a Unity sphere and name it ball. We will add a rigid body to it so that we can access the controller’s position and rotation. Then, add a similar ball directly on top of it and turn off the mesh renderer of the second ball. The purpose of the second ball is to provide us with the spawn position of the ball we throw.
You can also look at this STYLY Tutorial for more reference.
Once we have the controller model ready, let’s create another ball of the same size. This will be the projectile we throw.
Now that we have all the models ready, let’s begin using playmaker. If you haven’t installed Playmaker yet, please consult this guide. Once we have the playmaker set up, proceed by creating an empty object in Unity. Our intent is to add all necessary objects in this empty object, create its prefab and upload it to STYLY. Next add the modified stadium containing wickets into the empty object. The real purpose of playmaker starts from here.
Since we cannot write scripts in STYLY, we will use playmaker to take care of that part without a single line of code. We first create another empty object and name it BallController_R. This object will hold State machines dealing with the right controller. We will now proceed to do the following actions in the FSM:
- Find Game Object (Object name: “Controller (right)”, store in new variable “controller”)
- Get Position(Game Object: “controller”, store in new variable “controllerPosition”)
- Get Rotation(Game Object: “controller”, store in new variable “controllerRotation”)
- Create Object(Game Object “ball” prefab, with position : “controllerPosition” and rotation “controllerRotation”, store in “Ballcontroller”)
- Set Parent(set “controller” as parent of “Ballcontroller”)
- Get Child(Get child “spawnPoint” of object : “Ballcontroller”, store in new variable “spawnpoint”)
- Get Child(get child “Model” of object : “controller”, store in new variable “controllerModel”)
- Destroy Object(Destroy “controllerModel”)
Next, Add 2 Global Events “Global_TriggerPressDown_R” and “Global_TriggerPressUp_R”. These events are compatible with STYLY engine. We will use these events to trigger release of ball and will also use them to release one ball per throw.
Add 2 states waiting for trigger and create ball and add transition as shown in the picture.
Next, we want to create a ball which has the direction and velocity of the controller. To do so, add the following actions in state create ball:
- Get Velocity(of Object: “controller”, store in Vector in new variable “ball_Velocity”)
- Get Rotation(of Object: “spawnpoint”, store Euler Angles in new variable “spawnpointRotation”)
- Create Object(Game object: ball_game with Spawn point: “spawnpoint” and rotation as “spawnpointRotation”)
Now that we are able to create a new ball, we need to give it the velocity of the controller. We do so by adding a FSM in the object ball_game.
- Get FSM Variable(get object “ballController_R”, store in new variable “ball_Velocity”)
- Set Velocity(Set owner velocity to be “ball_Velocity”)
Our game is now set to play. Simply drag the object from hierarchy to assets to make it into a prefab. Finally upload the prefab to STYLY! Congratulations! You just made your first game in STYLY! Now open up STYLY editor, set and rotate the new imported model, Publish the scene and share it with your friends!