LeapMotionでつくるコンテンツのメモです。
LeapMotionの手の動きの取り方
スクリプトによる制御方法を知る場合,以下のドキュメントをみるほうがよいです。
https://leapmotion.github.io/UnityModules/namespaces.html
SDKがアップデートされていて,過去の記事のコードが参考にならない場合もあるのでドキュメントも目を通すといいと思います。
基本的に使うのはController,Frame,Hand,Fingerだという印象を受けました。
以下のスクリプトで,手の握った角度と強さがわかるようなので,ひとまずはこの値を使うと便利そうです。
GrabStrengthは[0,1]のfloat値で,実用上はこっちを使うほうがよさそうという印象。
Controller controller = new Controller();
private Frame frame;
void Update () {
if (controller.Frame() != null)
{
frame = controller.Frame();
foreach (Hand mhand in frame.Hands)
{
Debug.Log(mhand.GrabAngle+":"+mhand.GrabStrength);
}
}
手を広げかたでparticleの動作を制御
Controller controller = new Controller();
private Frame frame;
[SerializeField] ParticleSystem particle;
private void Start()
{
particle.Stop();
}
void Update () {
if (controller.Frame() != null)
{
frame = controller.Frame();
foreach (Hand mhand in frame.Hands)
{
Debug.Log(mhand.GrabAngle+":"+mhand.GrabStrength);
if (mhand.GrabStrength < 0.2)
{
particle.Play();
}
}
}
最終的に上記のようにすることでparticleの制御を手の動きでできるようにしました。
参考
- LeapMotionプログラミングガイド