簡體   English   中英

對象在-z和-x角的z軸上翻轉180度

[英]Object flips 180 degrees on z-axis in -z and -x corner

基本上我有一個旋轉的物體。 它是一種單擊和拖動類型的旋轉,但是當對象面向-z -x角或左下角時,再次單擊時,它有可能以相反的方式完全翻轉180度。 這非常麻煩,我甚至知道這發生了什么。這是點擊代碼:

void OnMouseDown() 
{
    Vector3 pos = Camera.main.WorldToScreenPoint(transform.position);
    pos = Input.mousePosition - pos;
    baseAngle = Mathf.Atan2(pos.y, pos.x) * Mathf.Rad2Deg;
    baseAngle -= Mathf.Atan2(transform.right.y, transform.up.x) * Mathf.Rad2Deg;
    startRotation = transform.rotation;
}

baseAngle - = Mathf.Atan2(transform.right.y,transform.up.x)* Mathf.Rad2Deg;

^^^這條線讓我頭疼。 我嘗試使用“.x”和“.z”結尾,但我無法理解。 當我用“.z”切換“.x”時,問題就出現在右下角。 如果我甚至搞砸了“.y”,我只能遠離我想要的東西。

圖片:

順便說一句,Z軸垂直向上,X軸水平向右。 任何幫助贊賞。

問題似乎是我錯過了.x,.y和.z的組合。 當我嘗試用“transform.up.y”替換“transform.up.x”時,我停止了這個問題。

暫無
暫無

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

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