【问题标题】:How Can I store the 2D Rotation in Unity?如何在 Unity 中存储 2D 旋转?
【发布时间】:2020-05-19 22:21:55
【问题描述】:

我需要从之前的位置转动轮子。但每次触摸屏幕时它都会重置。当触摸结束(释放)然后再次触摸时会出现问题。

我需要存储对象的旋转值。

任何帮助表示赞赏。谢谢


Video


direction = Camera.main.ScreenToWorldPoint(touch.position) - transform.position;
  angle = (Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg)-90;
  rotation = Quaternion.AngleAxis(angle, Vector3.forward);
  transform.rotation = Quaternion.Slerp(transform.rotation, rotation, speed * Time.deltaTime);
  oldRotation = transform.rotation;

【问题讨论】:

  • 您能否将其余代码添加到上下文中?特别是当问题在于您处理触摸时,例如处理触摸的部分会有所帮助......

标签: c# unity3d rotation transform


【解决方案1】:

该函数在什么事件中?一个更新? 很可能它在手指松开后至少执行一次,此时 touch.position 不再具有有效值。 首先检查用户是否真的在触摸,只有在这种情况下才执行代码。

【讨论】:

  • 它在 Update 和 TouchPhase.Moved 上
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-07-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多