【问题标题】:Creating Simple Endless Moving Platform with cubes用立方体创建简单的无尽移动平台
【发布时间】:2019-03-18 16:49:00
【问题描述】:

尝试创建simple endless moving platformz 上的比例为 70 的 3 个立方体(玩家不会向前移动,只会向左/向右移动)。 RepositionPlatform 脚本附加到每个负责移动的平台/立方体上,并检查每个平台的z position 是否为<= -100.0f, then position is changed to (0,0,200.0f).

问题是有时平台(多维数据集)之间有一点差距,或者有一点我不想要的重叠。

平台应该一个接一个地放置,没有任何间隙或重叠!!!

任何人都可以通过查看脚本来帮助找到问题或提出其他更好的方法吗?

下面的脚本附在3个平台游戏对象上!!!

public class RepositionPlatform : MonoBehaviour
{
    private GameObject platformGO;

    [SerializeField]
    private float speed;

    // Start is called before the first frame update
    void Start()
    {
        platformGO = this.gameObject;
        Debug.Log("In RepositionPlatform Start method - "+ platformGO.name);
    }

    // Update is called once per frame
    void Update()
    {

        Debug.Log("In RepositionPlatform Update Method- " + platformGO.name);

        platformGO.transform.Translate(Vector3.back * Time.deltaTime * speed);

        Transform platformTransform = platformGO.transform;
        if(platformTransform.position.z <= -100.0f)
        {
            platformTransform.position = new Vector3(0,0,200.0f);
        }
    }
}

【问题讨论】:

    标签: c# unity3d


    【解决方案1】:

    可能是因为速度是一个浮点值。如果您还没有阅读它们,您应该阅读它们。

    长话短说,您并没有考虑到值可能低于 -100 的程度,您只是在重置它。

    如果您改为翻译它,您将保留超过 -100 的任何额外距离,即转换可能已经过去。

    试试这个:

    If (transform.position.z < -100){
    
      transform.Translate(new Vector3(0,0,200));
    
    }
    

    编辑 应该是 Z 值,而不是 X

    【讨论】:

      猜你喜欢
      • 2012-02-27
      • 2021-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-21
      • 2019-08-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多