本文介绍了如何从触发器获取联系点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个2d传感器,它不会发生碰撞,但也会为我提供碰撞的接触点.

I'm in a situation where I need a 2d sensor that will not collide but will also give me contact points for a collision.

触发器不给我接触点,对撞机给我接触点,但会引起碰撞.

Triggers don't give me contact points and colliders give me contact points but cause a collision.

我已经尝试过使用碰撞器时禁用碰撞,以期使碰撞进入回调,但实际上并没有发生碰撞,但是没有运气.

I've tried disabling collisions when using colliders in the hopes of getting a collision enter callback but not having the collision actually occur, but no luck.

那么如何从触发器获取联系点?或者如何在不引起碰撞的情况下使用刚体获得碰撞回调?

So how do I get contact points from a trigger? Or how do I get a collision callback with rigidbodies without causing a collision?

基本上我有一个想充当雷达的圆圈,但我希望它在接触点方面也相当准确.

Basically I have a circle that I want to act as radar, but I'd like it to be fairly accurate with contact points too.

推荐答案

您应该使用OnCollisionEnter,但要添加一个rigidbody并将isTrigger设置为false,并将刚体isKinematic设置为true那么它将像触发器一样,您可以获得这样的联系点

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);
        }

这篇关于如何从触发器获取联系点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-14 12:52