【问题标题】:Unity's Transform.Translate moves on z axis when translating on xUnity Transform.Translate 在 x 上平移时在 z 轴上移动
【发布时间】:2016-09-05 20:39:33
【问题描述】:

今天,Unity 中的翻译功能在我的项目中显示出一些我以前从未经历过的奇怪行为。当我尝试使用Vector3.leftnew Vector3(-1, 0, 0) 将我的播放器向左平移时,它也在Z 轴上变为-1。当我向右走时也会发生同样的情况,在这种情况下,它在 Z 轴上移动 +1。

我尝试了很多方法,包括:

  • transform.Translate(-1, 0, 0);
  • transform.Translate(Vector3.left);
  • `transform.position += Vector3.left;'
  • transform.position = new Vector3(transform.position.x-1, transform.position.y, transform.position.z);
  • 我什至尝试过类似 `transform.Translate(-1, 0, 1);'没有成功
  • 问题不在于方向。 Space.world 或默认的 RelativeTo 参数 Space.self 不要修复它。

谁能帮助我进一步解决这个问题?我没办法……

【问题讨论】:

    标签: c# unity3d orientation


    【解决方案1】:

    使用

    transform.Translate(Vector3.right * Input.GetAxis("Horizontal"));
    transform.Translate(Vector3.up * Input.GetAxis("Vertical"));
    

    改为

    【讨论】:

    • 这种修复它但我需要它移动一个单位。您能否也解释一下为什么这是一个解决方案?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-17
    • 1970-01-01
    • 2019-08-14
    • 2019-08-14
    相关资源
    最近更新 更多