簡體   English   中英

如何在 Unity 中存儲 2D 旋轉?

[英]How Can I store the 2D Rotation in Unity?

我需要從以前的位置旋轉輪子。 但是每次觸摸屏幕時它都會重置。 當觸摸結束(釋放)然后再次觸摸時會出現問題。

我需要存儲對象的旋轉值。

任何幫助表示贊賞。 謝謝


視頻


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;

該函數在什么事件中? 一個更新? 很可能在松開手指后至少執行一次,此時 touch.position 不再具有有效值。 首先檢查用戶是否真的在觸摸,只有在這種情況下才執行代碼。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM