目次
VroidのアバターをUnityで動かす
VRoidで作成したアバターをUnityで動かします。
背景とモーションは、Unity Assetsからダウンロードし、VRoidで作成して、VRM書式で取り込んだアバーターを動かします。アバターを動かすScriptは、C#で作成しました。
![](https://lifeanddigital.net/wp-content/uploads/2023/07/2a831ec055ed4fee4e1d0936ea40500d-1-1024x709.jpg)
VRoidでアバターを作成する
Unityで取り込みできる3Dモデルを作ります。
アバターの作成方法をこちらを参考にしてください
あわせて読みたい
![](data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==)
![](https://lifeanddigital.net/wp-content/uploads/2023/07/Blog-Top-300x208.jpg)
アバターを作ってVRサイトで使う
メタバースサイト(Cluster)に自分で作ったアバターで参加しましょう アバターの作成には、VRoidを使います。 https://www.youtube.com/watch?v=E7_VVcy3iJk VRサー...
Vroid
VRoid Hub
![](data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==)
![](https://hub.vroid.com/public/images/ogp/default_ja.png)
VRoid Hub
VRoid Hubは、3Dキャラクターのための投稿・共有プラットフォームです。モデルデータをアップロードするだけでキャラクターが活き活きとアニメーションするプロフィールペ...
サンプルモデルを選択します。
![](https://lifeanddigital.net/wp-content/uploads/2023/07/5f63f49b6b7d98988e1002a4a4f2d6d5-1024x709.jpg)
VRM書式でエクスポートします。
![](https://lifeanddigital.net/wp-content/uploads/2023/07/04f86ea9c104d100d663feb8a9a65769-1-1024x709.jpg)
フォーマットの諸域を指定します。
![](https://lifeanddigital.net/wp-content/uploads/2023/07/63ead695680eb0c485fa3f134844052f-1024x709.jpg)
Unity Assetsの入手
下記のアセットを入手します。
Simple Low Poly Nature Pack
あわせて読みたい
![](data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==)
![](https://assetstorev1-prd-cdn.unity3d.com/key-image/0f30f8ad-1e54-4130-8b75-4f282e6ac251.jpg?v=1)
Simple Low Poly Nature Pack | 3D Landscapes | Unity Asset Store
Elevate your workflow with the Simple Low Poly Nature Pack asset from NeutronCat. Find this & other Landscapes options on the Unity Asset Store.
Basic Motions FREE
あわせて読みたい
![](data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==)
![](https://assetstorev1-prd-cdn.unity3d.com/key-image/a438f917-f2a2-4c35-8292-1c40971c46e4.png?v=1)
Basic Motions FREE | 3D Animations | Unity Asset Store
Elevate your workflow with the Basic Motions FREE asset from Kevin Iglesias. Find this & other Animations options on the Unity Asset Store.
Unityを起動します
Unity プロジェクトを作成します。 VRoidやBlenderで作成した人型3Dモデルを取り込む為にUnityに、UniVRMをインストールします。 3Dモデルが移動する為のステージを作成します。
![](https://lifeanddigital.net/wp-content/uploads/2023/07/7d2a8a5d380f463388d1c8d4512bef57-1-1024x709.jpg)
UnityとUnity AssetsのID登録
![](https://lifeanddigital.net/wp-content/uploads/2023/07/40dcbe9d88c96297b642179a653642d8-1-1024x709.jpg)
おもなAssets
RPG用パック Simple Low Poly Nature Pack https://assetstore.unity.com/packages/3d/environments/landscapes/simple-low-poly-nature-pack-157552 モーションキット Dance Animations FREE https://assetstore.unity.com/packages/3d/animations/dance-animations-free-161313 Basic Motions FREE https://assetstore.unity.com/packages/3d/animations/basic-motions-free-154271 Unity のスターターキット 一人称 Starter Assets - First Person Character Controller | URP https://assetstore.unity.com/packages/essentials/starter-assets-first-person-character-controller-urp-196525 三人称 Starter Assets - Third Person Character Controller https://assetstore.unity.com/packages/essentials/starter-assets-third-person-character-controller-196526 地面用テクスチャ Terrain Textures Pack Free https://assetstore.unity.com/account/assets Outdoor Ground Textures https://assetstore.unity.com/packages/2d/textures-materials/floors/outdoor-ground-textures-12555 制服ユニティちゃん https://unity-chan.com/download/releaseNote.php?id=TPK-Hmnd-Kohaku_B
Simple Low Poly Nature Packを使う
![](https://lifeanddigital.net/wp-content/uploads/2023/07/c64c5ece666a6407486987541305a212-2-1024x709.jpg)
Basic Motions FREEを使う
![](https://lifeanddigital.net/wp-content/uploads/2023/07/7ecbec8b200a97f5b85a8a31ece4115c-1024x709.jpg)
Unityでシーンを作る
![](https://lifeanddigital.net/wp-content/uploads/2023/07/9b4ccaedd1bef1dacccd44245c6b928f-1-1024x709.jpg)
UniVRMインポート
UniVRM ダウンロード
VRM 0.x Import/Export がVRoid対応になります。
GitHub
![](data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==)
Releases · vrm-c/UniVRM
UniVRM is a gltf-based VRM format implementation for Unity. English is here https://vrm.dev/en/ . 日本語 はこちら https://vrm.dev/ - vrm-c/UniVRM
![](https://lifeanddigital.net/wp-content/uploads/2023/07/1d88ceb91c7659c8f850f9acae163da9-2-1024x709.jpg)
UniVRMインポート
![](https://lifeanddigital.net/wp-content/uploads/2023/07/cb0bebe26f4ed333f0858ac401d32275-1024x709.jpg)
アバターをインポート
VRMフォーマットのファイルをAssetsの中にドラック&ドロップするとインポートされます。 インポートされると、アニメーション等が付随したPrefubが作成されます。 作成された、PrefubをHierarchyにドラック&ドロップします
![](https://lifeanddigital.net/wp-content/uploads/2023/07/c9552d0133d0f4a2a4f77168fb145539-1-1024x709.jpg)
MoveControllerの追加
MoveControllerを作成して、アバターの操作を行います。 WSADキーやアローキーでアバターの移動を行います。
1)Assets にScriptsフォルダーを作成 2)3DObject→Create→C# Scriptでスクリプトを作成 3)名前を”CameraScript”とします 4)CameScript を Hierarchy内の MainCamera へドラッグ&ドロップします 5)スクリプトのターゲットを【モデル名]にします
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MoveController : MonoBehaviour
{
private Animator animator;
// Start is called before the first frame update
void Start() {
animator = GetComponent<Animator>();
}
// Update is called once per frame
void Update() {
if (Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.W)) {
animator.SetBool("Walk", true);
transform.position += transform.forward * 0.01f;
} else {
animator.SetBool("Walk", false);
}
if (Input.GetKey(KeyCode.DownArrow) || Input.GetKey(KeyCode.S)) {
animator.SetBool("Back", true);
transform.position -= transform.forward * 0.01f;
} else {
animator.SetBool("Back", false);
}
if (Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.D)) {
transform.Rotate(0.0f, 1.0f, 0.0f);
}
if (Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.A)) {
transform.Rotate(0.0f, -1.0f, 0.0f);
}
}
}
![](https://lifeanddigital.net/wp-content/uploads/2023/07/285ad5b6b50d16ac0d0bca67c9e8953a-1-1024x709.jpg)
アバター へカメラの追従
スクリプトの作成
1)Assets にScriptsフォルダーを作成 2)3DObject→Create→C# Scriptでスクリプトを作成 3)名前を”CameraScript”とします 4)CameScript を Hierarchy内の MainCamera へドラッグ&ドロップします 5)スクリプトのターゲットを【モデル名]にします
![](https://lifeanddigital.net/wp-content/uploads/2023/07/45e645353c52af061f80af60f346190d-2-1024x709.jpg)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraScript : MonoBehaviour
{
public GameObject target;
private Vector3 distance;
// Start is called before the first frame update
void Start()
{
distance = transform.position - target.transform.position;
}
// Update is called once per frame
void Update()
{
transform.position = target.transform.position + distance;
}
}
TargetをモデルにするTargetをモデルにする
![](https://lifeanddigital.net/wp-content/uploads/2023/07/180801fa1135fb2f9b1d3ae25cb678f0-1-1024x709.jpg)
モーション追加
Animatorを選択する
![](https://lifeanddigital.net/wp-content/uploads/2023/07/3265133c13d3b0b9fb53d46133fc3b7b-1-1024x709.jpg)
モーションの切り替え
Animetor Contoler
![](https://lifeanddigital.net/wp-content/uploads/2023/07/84cf2338df598a65f7626d84e74cce87-1-1024x709.jpg)
床との緩衝
Rigidbody:物理法則を与える
アバターに物理法則を与えます。重力の影響を表現しますので、支えがないと自由落下します。
Freeze Rotation: X,Y,Z それぞれチェックを入れる
Capsule Collider:カプセル型の干渉の形状
自由落下するアバターが地面にあたる(干渉)する事をチェックして落下を止めます
Center : X=0,Y=0.85,X=0 Height: 1.75
![](https://lifeanddigital.net/wp-content/uploads/2023/07/1e747160b568df1ae5b7e89208dffdcd-1-1024x709.jpg)
完成
![](https://lifeanddigital.net/wp-content/uploads/2023/07/1e747160b568df1ae5b7e89208dffdcd-2-1024x709.jpg)
コメント