如何使用GPS坐标在Vector3移动玩家?(团结)



我需要开发一个Unity Android APP来帮助农业指导,我面临一些非常具体的GPS问题,让我来解释一下这个项目。

  1. 它需要使用精确的GPS数据来指导您的领域
  2. 它不能连接以太网,我只得到纬度和经度,地图只是一个无限的地平面(已经)而不是真实世界的地图。
  3. "player"(拖拉机,机器,…)需要在Unity上移动空间(不是地面纹理,而是玩家本身),因为我需要绘制Trail渲染器我的种植路径(已经制作)。

所以我有一个非常特殊的情况,我找到的每个API移动地面纹理而不是玩家对象。我需要将纬度和经度的变化(移动)转换为Unity空间的移动,我需要在每次GPS坐标变化时准确地在Vector3坐标上移动(transform. translate)我的玩家。这段代码是关于我现在拥有的。

//so in the Update method
if (newLat != lastLat || newLong != lastLong){
//what do I do here?

编辑1:这个人在以前的帖子里有和我一样的问题,但是没有得到回应。

读完这段代码后,我认为你可以只获得纬度和经度和设置位置不移动.

我的意思是这样的:

// Get the GPS values (I'm not sure if you can do it like this, I copied it from the code you linked)
latitude = Input.location.lastData.latitude;
longitude = Input.location.lastData.longitude;
// Set the position of a GameObject using the GPS values
transform.position = new Vector3(latitude , 0, longitude);

最新更新