简体   繁体   中英

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. 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()

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

// Pose callbacks from 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? I have attached this script to my Capsule rigidbody.

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. The FixedUpdate method is used for any physics related changes and is called at a fixed rate whereas Update is dependent on framerate.

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.

I do not know anything about "Tango" but you code will be similar to the following untested code:

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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