【问题标题】:Orbiting an object in Vuforia using c# Unity使用 c# Unity 在 Vuforia 中环绕对象
【发布时间】:2020-05-28 14:45:59
【问题描述】:

我在 c# 中为 Unity 编写了一个简单的脚本,用于在图像目标上方制作一个类似于球体轨道 (0,0,0) 的 3D 对象。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Vuforia;

public class Orbit : MonoBehaviour
{
    float angles;
    float radiuss;
    float angleSpeed;

    // Start is called before the first frame update
    void Start()
    {
        angles = 0;
        radiuss = 0.2f;
        angleSpeed = 1;

    }

    // Update is called once per frame
    void Update()
    {
        angles += Time.deltaTime * angleSpeed;


        float x = radiuss * Mathf.Cos(Mathf.Deg2Rad * angles);
        float z = radiuss * Mathf.Sin(Mathf.Deg2Rad * angles);
        float y = 1*0;

        transform.position = new Vector3(x, y, z);
    }
}

如果不用于 Vuforia,该脚本可以正常工作,但是当我将它添加到 Vuforia 的对象时,它的行为很奇怪,并且不遵循脚本描述的路径。

这些是配置和层次结构。

请帮忙。

【问题讨论】:

    标签: c# unity3d vuforia


    【解决方案1】:

    您应该在您的 vuforia 配置中检查世界中心是如何受到影响的。我认为它在 AR 相机中,您有一个组件“Vuforia Behaviour”。你有一个参数“世界中心模式”。默认情况下,它是您的设备:

    这意味着您的相机始终是原点,因此,当您在现实世界中移动手机或相机时,实际上是在“统一世界”中移动的对象(它们的位置根据相机的变化) .

    尝试改变:

    transform.position = new Vector3(x, y, z);
    

    进入:

    transform.localposition = new Vector3(x, y, z);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多