HTC Vive, animation, Masanori Takano, playMaker, Unity,

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.

完成シーン

The completed scene

 

View the sample asset by WebEditor

View the sample asset by WebEditorLaunch the 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 create a new STYLY account >>
Click here

 

Samples

You can taste the sample space from STYLY GALLERY.

Gallery Page

You can download the Unity project introduced in this article.

Sample Project

 

Required Assets

In this article, we use Playmaker.

Playmakerを使用します

Playmaker is used.

 

For the characters, we use a motion available in Move Motion Free Pack.

Move Motion Free Pack

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

リグの設定

The setting for ‘Rig’

Add Animator Controller

To control the animation, add ‘Animator Controller’.

Select ‘Create > Animator Controller’. I named it ‘Nakagawa’ here.

Animator Controllerの追加

Add ‘Animator Controller’.

 

Set the created Animator Controller (Nakagawa.control) for ‘Controller’ of the Animation component.

Check the ‘Apply Root Motion’ box.

Controllerの指定

Set ‘Controller’.

 

The setting for Animator

Select ‘Window > Animator’ to open the Animator window.

Right-click and select ‘Create State > Empty’ to create an Empty State.

Stateの追加

Add ‘State’.

 

Select the ‘New State’ created.

New Stateを選択

Select ‘New State’.

 

Set the motion you want to use, for ‘Motion’ in the Inspector.

This time, I use ‘Basic_Walk_01’ in ‘Move Motion Free Pack’.

Motionを指定する

Specify the motion you want to use.

 

Play the game to check whether the motion is assigned correctly.

The walking motion looks working well.

Motionが適用された

The motion is applied.

 

The settings for Playmaker

Add State

Convert the character with the motion into a prefab.

Create the ‘Prefabs’ folder and drag the character into it.

プレハブにする

Convert into a prefab.

 

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.

空のオブジェクトを作ってプレハブにする

Create an empty object and convert it 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.

Rigidbodyの追加

Add a Rigidbody

 

Name the created sword ‘Sword’ and convert it into a prefab.

プレハブにする

Convert ‘Sword’ into a prefab.

 

Add Action

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.

Find Game objectの追加

Add the ‘Find Game object’ component.

 

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.

Create Objectの追加

Add the ‘Create Object’ component.

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.

Set Parentの追加

Add the ‘Set Parent’ component

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

Transitionの追加

Add ‘Transition’.

 

Right-click and select ‘Add State’ to create a new state, ‘Stage2’.

Drag the ‘FINISHED’ transition of ‘State1’ into ‘State2’ to connect them.

Stateを追加

Add a new state.

This enables the transition to ‘State2’.

 

Create Character

Rename State2 ‘Character Generation’ and make this state generate a character.

Stateの名前を変更

Rename ‘State2’.

Add the ‘Create Object’ component.

Select ‘Nakagawa’  in the Game Object field.

Create Objectの追加

Add the ‘Create Object’ component

 

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.

Random Floatの追加

Add the ‘Random Float’ component

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.

Set Vector3 XYZの追加

Add the ‘Set Vector3 XYZ’ 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.

Positionの変数を指定

Select the ‘NakagawaPos’ variable for ‘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.

Random Waitの追加

Add the ‘Random Wait’ component.

 

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

Character Generationに戻す

Go back to ‘Character Generation’.

 

Play the game on Unity. Now you can see the characters are generated at random positions.

再生した結果

How it looks when the game is played.

 

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.

How to create ‘Dy*asty Warriors’ VR with STYLY and Unity’s Playmaker Vol.2 – ‘Look At’ and ‘Collison Enter’ –

 

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.

Masanori Takano

牧場厩務員→家具職人→大工を経て現在はフリーランスの3DCGアーティスト

Share this article

Shares
Facebook Twitter Google+ Pinterest hatebu

About STYLY

STYLY is a cloud-based service for creating high quality,beautiful VR spaces that doesn’t require any coding. By using STYLY, creators can express their imaginations indefinitely and build a variety of virtual spaces. Through these spaces, we can share experiences that are unachievable in the real world.