简体   繁体   English

刚体不碰撞-Unity Project Tango

[英]Rigid Body not colliding - Unity Project Tango

I created a RigidBody in Unity3D and attached a controller script to it which will control the movement of the body through Tango Motion Control. 我在Unity3D中创建了RigidBody,并在其上附加了控制器脚本,该脚本将通过Tango Motion Control控制身体的运动。 But the problem is that for some reason, my rigibody does not collide with the walls that I have on the side. 但是问题在于,由于某种原因,我的刚体没有与侧面的墙壁发生碰撞。 It just passes through it. 它只是通过它。

Here is my code snippet for Update() 这是我的Update()代码段

void Update()
    {
        Debug.Log("Tango update: " + m_tangoPosition + " " + m_tangoRotation);    

        PoseProvider.GetMouseEmulation(ref m_tangoPosition, ref m_tangoRotation);
        transform.position = m_tangoPosition + m_startPosition;
        transform.rotation = m_tangoRotation;
}

I get my TangoPose data through the OnPoseAvailable call back 我通过OnPoseAvailable回叫获取TangoPose数据

// Pose callbacks from Project Tango //来自Project Tango的姿势回调

    public void OnTangoPoseAvailable(Tango.TangoPoseData pose)
    {
        // Do nothing if we don't get a pose
        if (pose == null)
        {
            Debug.Log("TangoPoseData is null.");
            return;
        }
        // The callback pose is for device with respect to start of service pose.
        if (pose.framePair.baseFrame == TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_START_OF_SERVICE &&
            pose.framePair.targetFrame == TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_DEVICE)
        {
            if (pose.status_code == TangoEnums.TangoPoseStatusType.TANGO_POSE_VALID)
            {

                // Cache the position and rotation to be set in the update function.
                m_tangoPosition = new Vector3((float)pose.translation [0],
                                              (float)pose.translation [1],
                                              (float)pose.translation [2]);

                m_tangoRotation = new Quaternion((float)pose.orientation [0],
                                                 (float)pose.orientation [1],
                                                 (float)pose.orientation [2],
                                                 (float)pose.orientation [3]);
//                Debug.Log("Tango VALID pose: " + m_tangoPosition + " " + m_tangoRotation);
            }
        }
    }

Am I missing something here ? 我在这里想念什么吗? Why does my RigidBody go through the walls? 为什么我的RigidBody穿过墙壁? I have attached this script to my Capsule rigidbody. 我已将此脚本附加到Capsule刚体上。

Any help or pointers are greatly appreciated. 任何帮助或指针,我们将不胜感激。

Thanks 谢谢

You'll want to make changes to rigidbody position and rotation in the FixedUpdate method rather than Update. 您将要在FixedUpdate方法而不是Update中更改刚体的位置和旋转。 The FixedUpdate method is used for any physics related changes and is called at a fixed rate whereas Update is dependent on framerate. FixedUpdate方法用于任何与物理相关的更改,并以固定速率调用,而Update取决于帧速率。

Furthermore, you are changing the transform's position. 此外,您正在更改变换的位置。 This is essentially teleporting the object. 这本质上是在传送物体。 If you want to move the rigidbody and still have collision, check out the MovePosition and MoveRotation methods on the rigidbody component. 如果要移动刚体并仍然有碰撞,请检查刚体组件上的MovePosition和MoveRotation方法。

I do not know anything about "Tango" but you code will be similar to the following untested code: 我对“ Tango”一无所知,但您的代码将类似于以下未经测试的代码:

public Rigidbody rigidbody;
void Start()
{
    rigidbody = GetComponent<Rigidbody>();
}

void FixedUpdate()
{
    //Other code here
    rigidbody.MovePosition(m_tangoPosition + m_startPosition);
    rigidbody.MoveRotation(m_tangoRotation);
}

I hope I have helped you! 希望我能对您有所帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM