gpt4 book ai didi

collision-detection - 如何从 hit.normal 中找到对撞机的哪一侧被击中?

转载 作者:行者123 更新时间:2023-12-04 00:47:02 26 4
gpt4 key购买 nike

在 Unity3d 中,我可以使用 hit.normal 获取对撞机与之碰撞的表面的法线,但是有没有办法找到哪一侧被 Unity3d 提供的东西击中了?

一种解决方案是查看法线的方向,并且应该适用于静态对象,但对于方向发生变化的动态和移动对象呢?

最佳答案

function OnCollisionEnter(collision : Collision)
{
var relativePosition = transform.InverseTransformPoint(collision.contacts);

if(relativePosition.x > 0)
{
print(“The object is to the right”);
}
else
{
print(“The object is to the left”);
}

if(relativePosition.y > 0)
{
print(“The object is above.”);
}
else
{
print(“The object is below.”);
}

if(relativePosition.z > 0)
{
print(“The object is in front.”);
}
else
{
print(“The object is behind.”);
}
}

关于collision-detection - 如何从 hit.normal 中找到对撞机的哪一侧被击中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7447271/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com