我寻找最好的方法来检测GO (立方体)的哪个位置朝上。我的研究让我找到了Dot-product。我知道我想做什么,但我想我的c#技能太差了。
基本上,我只想找出点积,例如x旋转。如果它的值在0,9到1之间,一个站点是朝上的,另一个站点是-0,9到-1,以此类推,对于所有轴。
发布于 2021-01-21 01:13:12
在Unity的文档中,您有以下example。你只需要稍微调整一下,就可以达到你需要的效果。
// detects if other transform is behind this object
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour
{
public Transform other;
void Update()
{
if (other)
{
Vector3 forward = transform.TransformDirection(Vector3.forward);
Vector3 toOther = other.position - transform.position;
if (Vector3.Dot(forward, toOther) < 0)
{
print("The other transform is behind me!");
}
}
}
}https://stackoverflow.com/questions/65814222
复制相似问题