如何统一制作自定义脚本对撞机?

问题描述 投票:0回答:0

我正在尝试编写自己的 AABB 算法进行碰撞检测,我希望刚体组件在不使用对撞机组件的情况下与我的 sqript 发生碰撞

 public class coliider : Collider
{
public float width;
public float height;
public float depth;
// Start is called before the first frame update
public bool Overlaps(coliider otherCollider)
{
    float distanceX = Mathf.Abs(transform.position.x - otherCollider.transform.position.x);
    float distanceY = Mathf.Abs(transform.position.y - otherCollider.transform.position.y);
    float distanceZ = Mathf.Abs(transform.position.z - otherCollider.transform.position.z);

    float combinedWidth = (width + otherCollider.width) / 2;
    float combinedHeight = (height + otherCollider.height) / 2;
    float combinedDepth = (depth + otherCollider.depth) / 2;
    return distanceX < combinedWidth && distanceY < combinedHeight && distanceZ < combinedDepth;
}
}
c# unity3d
© www.soinside.com 2019 - 2024. All rights reserved.