In this article, I introduce how to create a game like ‘Dy*asty Warriors’ with Unity’s Playmaker.
We place the enemy characters at random places and make them come toward the player.
Let’s create a fun game that you can beat a lot of enemy characters that disappear when you hit them with your weapon.
View the sample asset by WebEditor
※If you have your STYLY account, you can view the sample asset created in this article by WebEditor.
If you don’t, create a new STYLY account and then press the button above.
You can taste the sample space from STYLY GALLERY.
You can download the Unity project introduced in this article.
In this article, we use Playmaker.
For the characters, we use a motion available in Move Motion Free Pack.
The setting for the character
The setting for ‘Rig’
Import the human character with bones and bone-weight map into Unity.
Set ‘Animation Type’ to ‘Humanoid’ on the Rig page in the Inspector.
If you set ‘Avatar Definition’ to ‘Create From This Model’, the Animator component is added automatically.
I named the character ‘Nakagawa’.
Add Animator Controller
To control the animation, add ‘Animator Controller’.
Select ‘Create > Animator Controller’. I named it ‘Nakagawa’ here.
Set the created Animator Controller (Nakagawa.control) for ‘Controller’ of the Animation component.
Check the ‘Apply Root Motion’ box.
The setting for Animator
Select ‘Window > Animator’ to open the Animator window.
Right-click and select ‘Create State > Empty’ to create an Empty State.
Select the ‘New State’ created.
Set the motion you want to use, for ‘Motion’ in the Inspector.
This time, I use ‘Basic_Walk_01’ in ‘Move Motion Free Pack’.
Play the game to check whether the motion is assigned correctly.
The walking motion looks working well.
The settings for Playmaker
Convert the character with the motion into a prefab.
Create the ‘Prefabs’ folder and drag the character into it.
We create a new object and add the state of Playmaker to it.
Select ‘GameObject > Create Empty’ to create an empty object and name it ‘STYLYmusou’.
Drag it into the Prefabs folder to covert into a prefab.
With ‘STYLYmusou’ in the Prefabs folder selected, right-click on the Playmaker window and select ‘Add FSM’.
It creates a state.
When you select the prefab with an FMS added in the Hierarchy window and try to edit it by Playmaker, you will see a message, ‘Editing of Prefab Instance is disabled. See preferences’.
In that case, select ‘Edit Prefab’.
We will edit only the prefabs at this point onward.
Create a sword
With Unity, we create a sword to defeat the enemy.
I prepared a simple elongated Cube.
Asset Store has a lot of sword-type weapons, so it’s also a good idea to use one of them.
To detect the collision, add a Rigidbody and check the ‘Is Kinematic’ box.
Uncheck the ‘Use Gravity’ box.
Name the created sword ‘Sword’ and convert it into a prefab.
We add actions with Playmaker.
Firstly, acquire the VR controller by using ‘Find Game Object’.
By using this component, we deal with the sword as the child element of this acquired controller.
Enter ‘Controller (right)’ in the ‘Object Name’ field. Note that there is a space between ‘Controller’ and ‘(right)’.
In the ‘Store’ field, create a new variable, ‘Controller’, by ‘New Variable’ and select it.
Add the ‘Create Object’ component to generate an object.
Set the ‘Sword’ prefab for ‘Game Object’.
In the ‘Store Object’ field, create a variable, ‘Sword’, by ‘New Variable’ and select it.
Add the ‘Set Parent’ component to set the parent-child relationship between ‘Controller’ and ‘Sword’.
Set ‘Game Object’ to ‘Sword’, and ‘Parent’ to ‘Controller.
Check the ‘Reset Local Position’ and ‘Reset Local Rotation’ box.
It finishes the setting for the controller and the sword.
Add ‘Transition’ to trigger the transition of the state.
Right-click ‘State1’ and select ‘Add transition > FINISHED’.
Right-click and select ‘Add State’ to create a new state, ‘Stage2’.
Drag the ‘FINISHED’ transition of ‘State1’ into ‘State2’ to connect them.
This enables the transition to ‘State2’.
Rename State2 ‘Character Generation’ and make this state generate a character.
Add the ‘Create Object’ component.
Select ‘Nakagawa’ in the Game Object field.
Generate the X and Y value to set the position where the character is generated.
Use ‘Random Float’ to generate the character at a different place every time.
Set ‘Min’ and ‘Max’ to -10 and 10 respectively to generate the value between -10 and 10.
In the ‘Store Result’ field, create X and Z by ‘New Variable’ and select them.
It generates the randomized X and Z value every time.
Use ‘Set Vector3 XYZ’ to store the X and Z value together.
In the ‘Vector3 Variable’ field, create ‘NakagawaPos’ by ‘New Variable’ and select it.
Set ‘X’ and ‘Z’ to the X and Z generated by the Random Float component.
Select the ‘NakgawaPos’ variable for the ‘Position’ in the ‘Create Object’ component.
It’s now ready to generate the character at a random position.
Add the FINISHED transition to ‘Character Generation’.
Create a new state and name it ‘Random Wait’.
Connect ‘Character Generation’ to ‘Random Wait’.
For the Random Wait component, set ‘Min’ and ‘Max’ to 1 and 3 respectively to generate a random value between 1 second and 3 seconds so that it varies the timing when the character is generated.
Check the ‘Real Time’ box.
Once the random waiting time finished, the FSM goes back to ‘Character Generation’ to generate a character.
Add the FINISHED transition to ‘Random Wait’ and connect it to ‘Character Generation’.
Play the game on Unity. Now you can see the characters are generated at random positions.
How to upload an asset from Unity to STYLY.
Read the article
In this article, I explained how to import the separate asset of animation into Unity and generate characters at random positions with Playmaker.
As you know, random behaviour is often required for games.
In addition, it’s painful to create a lot of motions by yourself, although you always need to add motions to a character.
In that case, the motions in Unity Asset Store are very useful because you can apply them to your character in the same way that I introduced in this article.
In the next article, I will show how to ‘defeat’ the enemy characters getting close to you.
The 3D model used in this article can be found in the sample project.
Only in STYLY, you can use this 3D model.
As long as you use it in STYLY, you can modify it without any restrictions.