有關Kinect结合Unity3D引擎开发体感游戏(二)

发布于 2021-11-25 18:07:34 字数 5885 浏览 937 评论 1

@地瓜儿 你好,想跟你请教个问题:

依照您定義的我建立kinectMoving.cs

Kinect结合Unity3D引擎开发体感游戏(二)

我建立一個terrain的scene, 拉入一個Hierarchy組件(如cubes, 內包含階層cube, 準備對應head, spine, ...)

拉入kinectPrefab, 

連接好Kinect設備, 跑Kinect结合Unity3D引擎开发体感游戏(二)rainbowMan_v6正常, 

但跑自訂的scene後, cubes都不會動, 求助

// kinectMoving .cs

using UnityEngine;

using System.Collections;
using Kinect;
public class kinectMoving : MonoBehaviour {
    public int state = 0;
    public float moveSpeed = 12f;
    public SkeletonWrapper sw;
    public GameObject Hip_Center;
    public GameObject Spine;
    public GameObject Head;
    public GameObject Hand_Left;
    public GameObject Hand_Right;
void Start () {
}
// Update is called once per frame
void Update () {
        JuAction();
}
    public void setHeroState(int newState)
    {
        int rotationValue = (newState - state) * 90;
        Vector3 transformValue = new Vector3();
        animation.Play("rainbowMan_v6A");
        switch (newState)
        {
            case 0:
                transformValue = Vector3.forward * 10;  // Time.deltaTime;
                break;
            case 1:
                transformValue = -Vector3.forward * 10;  // Time.deltaTime;
                break;
            case 2:
                transformValue = Vector3.left * 10;  // Time.deltaTime;
                break;
            case 3:
                transformValue = -Vector3.left * 10; // Time.deltaTime;
                break;
        }
        transform.Rotate(Vector3.up, rotationValue);
        transform.Translate(transformValue * moveSpeed, Space.World);
        state = newState;
        
    }
    private void JuAction()
    {
        Vector3 hip=Hip_Center.transform.position;
        Vector3 handRight = Hand_Right.transform.position;
        Vector3 handLeft = Hand_Left.transform.position;
        Vector3 spine = Spine.transform.position;
        Vector3 head = Head.transform.position;
        bool flag;
        if (handLeft.y > spine.y - 0.1 || handRight.y > spine.y - 0.1)
            flag = true;
        else
            flag = false;
        if (flag)
        {
            if (head.x < spine.x - 0.2)
            {
                setHeroState(0);
                Debug.Log("Left ... ...");
            }
            if (head.x > spine.x - 0.2)
            {
                setHeroState(1);
                Debug.Log("Right ... ...");
            }
            if (head.z < spine.z - 0.1)
            {
                setHeroState(2);
                Debug.Log("Front ... ...");
            }
            if (head.z > spine.z - 0.1)
            {
                setHeroState(3);
                Debug.Log("Back ... ...");
            }
        }
    }
}


如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

屌丝范 2021-11-26 03:27:24

当然的 这个是需要与人物的骨骼绑定的 你后面用的没有这些绑定 后面动的话 可以用别的方法

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文