How to get contact points from a trigger?

拥有回忆 提交于 2019-12-05 04:50:30

You should use OnCollisionEnter but add a rigidbody to it and set isTrigger to false and set rigidbody isKinematic to true then it will act like a trigger and you can get the contact points like this

 void OnCollisionEnter(Collision collision) {
        foreach (ContactPoint contact in collision.contacts) {
            Debug.DrawRay(contact.point, contact.normal, Color.white);
        }

You can get point of contact using OnTriggerEnter function

OnTriggerEnter(Collider other)
{
    RaycastHit hit;
    if (Physics.Raycast(transform.position, transform.forward, out hit))
    {
        Debug.Log("Point of contact: "+hit.point);
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!