首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Unity 3d GO方向

Unity 3d GO方向
EN

Stack Overflow用户
提问于 2021-01-21 01:08:16
回答 1查看 24关注 0票数 0

我寻找最好的方法来检测GO (立方体)的哪个位置朝上。我的研究让我找到了Dot-product。我知道我想做什么,但我想我的c#技能太差了。

基本上,我只想找出点积,例如x旋转。如果它的值在0,9到1之间,一个站点是朝上的,另一个站点是-0,9到-1,以此类推,对于所有轴。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-01-21 01:13:12

在Unity的文档中,您有以下example。你只需要稍微调整一下,就可以达到你需要的效果。

代码语言:javascript
复制
// 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!");
            }
        }
    }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65814222

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档