LoginSignup
6
0

More than 3 years have passed since last update.

ボクもやりたい☆てのりカナヅチくん!!

Last updated at Posted at 2020-08-04

概要

この記事は「マイスター・ギルド:暑中見舞!夏のアドベントカレンダー2020」2日目の記事です

とある日

(๑و•̀ω•́)و |Twitter|
(๑و•̀ω•́)و < て、てのりカナヅチくーん
(๑و•̀ω•́)و < ボクも!ボクも!

手乗りカナヅチと書いてあったので作ってみた

開発環境

項目 バージョン 備考
Unity 2019.2.21f1
MRTK 2.4

目標

右手にカナヅチくんを呼び出す
1. コードから右手のTransformを取得(Palm)
2. カナヅチくんを配置する

手順

  • スクリプトを作成
HandJoint.cs
using Microsoft.MixedReality.Toolkit.Input;
using Microsoft.MixedReality.Toolkit.Utilities;
using UnityEngine;

public class Sample : MonoBehaviour
{
    [SerializeField] GameObject _penguinObject = null;

    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        if (HandJointUtils.TryGetJointPose(TrackedHandJoint.Palm, Handedness.Right, out MixedRealityPose pose))
        {
            _penguinObject.transform.position = pose.Position + -pose.Up * 0.022f;
            _penguinObject.transform.rotation = pose.Rotation * Quaternion.Euler(new Vector3(-180, 0, 0));

            var currentVec = pose.Position + -pose.Up;
            var baseVec = pose.Position + Vector3.up;
            var dot = Vector3.Dot(currentVec, baseVec);
            _penguinObject.SetActive(dot > 0.60f);
        }
        else
        {
            _penguinObject.SetActive(false);
        }
    }
}
  • 任意のゲームオブジェクト作成
    コメント 2020-07-30 165158.png

  • 上記スクリプトを貼り付けます
    コメント 2020-07-30 165120.png

  • インスペクタから表示したいオブジェクトを設定
    コメント 2020-07-30 165224.png

完成

f1e7389e-161e-4fb9-b245-487a67e0d435-960x898r.png

次回

マイスター・ギルド次回アドカレ! SkyWayによるビデオ・音声通話の技術概要 ロイックさんです。

6
0
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
6
0