LoginSignup
5
6

More than 5 years have passed since last update.

ユニティちゃんを走らせてみた

Last updated at Posted at 2016-04-13

昼休みにふと思いついて
ひたすらユニティちゃんを走らせるようにしてみた。

動画

IMAGE ALT TEXT HERE

8秒ごとに位置を変えるボールに向かってユニティちゃんが走っていきます。

ダウンロード (Unityパッケージ)はこちら

Unity_FootstepsADX2LE_tatmos.unitypackage

上記パッケージをインポートして自由に使っていただいて構いません。
ってか遊んでみてね。

ksilogicさんのQiita記事
超使えるフリーサウンド素材集 OculusAudioPack01を効果的に使ってみよう」から
プロジェクトを拝借して改変しています。
足音ついているだけでも大分いい感じで、
床属性で音が変わるのでなんだか楽しい。

これを自動で走らせることにしてみました。

 走らせるためにナビメッシュ使ってみた

unity 経路探索でググるといろいろでてきたので参考に動かしている。

床とか壁とかを選択して「Navigation Static」とし、Bakeする。

image

image

あと、ユニティちゃんにもスクリプトをつけて

image

MoveToTarget.cs
using UnityEngine;
using System.Collections;

public class MoveToTarget : MonoBehaviour {
    public Transform target;
    NavMeshAgent agent;

    void Start () {
        Reset();
    }

    void Update () {
        agent.SetDestination(target.position);

        animator.SetFloat("Speed", agent.velocity.sqrMagnitude);
    }

    [SerializeField, HideInInspector] Animator animator;

    void Reset()
    {
        agent = GetComponent<NavMeshAgent>();
        animator = GetComponent<Animator>();
    }
}

ターゲットのSphereにもスクリプトつけて

image

RandomMove.cs
using UnityEngine;
using System.Collections;

public class RandomMove : MonoBehaviour {
    void Start () {
        Reset();
    }

    float lastMoveTime = 0f;

    void Update () {
        if(Time.timeSinceLevelLoad > lastMoveTime)
        {
            Reset();
        }
    }

    void Reset()
    {
        this.transform.localPosition = new Vector3(Random.Range(0,5),5,Random.Range(0,-50));
        lastMoveTime = Time.timeSinceLevelLoad+8;
    }

    // 接地したら
    void OnCollisionEnter (Collider col){
        if(col.tag != "ground")
        {
            Reset();
        }
    }
}

完成

足音変わるだけでもずいぶん楽しい。
ただ、アニメーションとかまだ不自然なところとかどうしたものか・・・もっと驚いてくれたり喜んでくれたりとか・・・

5
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
6