【问题标题】:Am trying to create a 3d compass in unity, but the needle fails to rotate along with the body of the compass我试图统一创建一个 3d 指南针,但针无法与指南针的主体一起旋转
【发布时间】:2021-10-09 18:00:04
【问题描述】:

我试图统一创建一个 3d 指南针,但指针无法与指南针主体一起旋转/倾斜。指针准确地指向北方的“空游戏对象”。但唯一的问题是它无法与指南针主体一起倾斜/旋转(向上或向下)。下面是d脚本

    public class AmpCompass : ResetObject
{
    public Transform target, compassNeedle;
    public float speed = 1.0f;
    private void Start() {
        
    }

    protected override void ObjectIsGrabbed()
    {        
        base.ObjectIsGrabbed();
    } 

    private void Update() 
    {

        Vector3 needleDir = new Vector3(target.position.x, compassNeedle.position.y, target.position.z);
        compassNeedle.LookAt(needleDir);
    }   
}

【问题讨论】:

    标签: c# unity3d rotation virtual-reality compass


    【解决方案1】:

    虽然我不太了解你的游戏对象的结构,但我的理解是你想让这个指南针在水平面上旋转。
    但是,如果你想手动形成一个 Vector3 并进行这个变换来查看这个坐标,你为什么选择保持它的'Y coordinate?因为我猜你想维护Z coordinate,因为冻结Horizontal Level,这意味着你应该在Update()方法中这样做:

    Vector3 needleDir = new Vector3(target.position.x, target.position.y, compassNeedle.position.z);
    compassNeedle.LookAt(needleDir);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-08-02
      • 1970-01-01
      • 2014-11-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-25
      相关资源
      最近更新 更多