簡體   English   中英

播放器旋轉視野

[英]Rotating field of view with player

因此,我試圖創建一個系統來尋找要爬的壁架。 我有一個垂直的視野可以尋找這些壁架,到目前為止,我已經使其沿模擬搖桿的方向旋轉,因此我可以找到一個壁架並移動到模擬物指向的位置。 (查找,查找壁架,向上移動等)。 我的問題是,當視野移動到需要移動的位置時,它保持固定在一個軸上,並且不會隨播放器旋轉。

到目前為止我有什么

在圖片中,圓錐體朝向應該放置的位置,並按照我想要的方向圍繞播放器旋轉,但是如您所見,圓錐體面向X軸並且不會從那里移動。 我希望它隨播放器一起旋轉。

在下面的代碼中,返回的Vector的y值使圓錐點向上。 我已經嘗試了x和z值中所有形式的函數,但沒有任何問題。

public Vector3 DirFromAngle(float angleInDegrees, bool angleIsGlobal)
{
    if(!angleIsGlobal)
    {
        angleInDegrees += (viewDir + 90);
    }

    Vector3 newValue = new Vector3(0, Mathf.Sin(angleInDegrees * Mathf.Deg2Rad), Mathf.Cos(angleInDegrees * Mathf.Deg2Rad));
    return newValue;
}

viewDir值使圓錐體隨着我的模擬棒旋轉,使圓錐體隨我的播放器旋轉,我假設需要使用x或z值或同時使用這兩個值來做某件事,但是對於我來說,我可以t弄清楚。 感謝您在此問題上的任何幫助。 抱歉,如果我的解釋不是很好。

在此處輸入圖片說明 在此處輸入圖片說明

void OnSceneGUI()
    {
        LedgePointSearch lps = (LedgePointSearch)target;
        Handles.color = Color.white;
        Handles.DrawWireArc(lps.transform.position, lps.transform.forward * 90, Vector3.up, 360, lps.viewRadius);
        Vector3 viewAngleA = lps.DirFromAngle(-lps.viewAngle / 2, false);
        Vector3 viewAngleB = lps.DirFromAngle(lps.viewAngle / 2, false);

        Handles.DrawLine(lps.transform.position, lps.transform.position + viewAngleA * lps.viewRadius);
        Handles.DrawLine(lps.transform.position, lps.transform.position + viewAngleB * lps.viewRadius);
    }

這是顯示視野的編輯器腳本。

圓僅表示視場的半徑,其走多遠。

https://www.dropbox.com/s/k9siha2aog9vj8o/fov.mp4?dl=0

在視頻中,圓圈隨播放器旋轉,圓錐隨我的左模擬動作旋轉。 我希望圓錐像圓一樣,隨着玩家的旋轉而旋轉,但仍與模擬運動匹配。

一種解決方法是找到播放器的Y旋轉並將其應用於newValue然后再將其返回。

public Vector3 DirFromAngle(float angleInDegrees, bool angleIsGlobal)
{
    if(!angleIsGlobal)
    {
        angleInDegrees += (viewDir + 90);
    }

    Vector3 newValue = new Vector3(0, Mathf.Sin(angleInDegrees * Mathf.Deg2Rad), Mathf.Cos(angleInDegrees * Mathf.Deg2Rad));

    // get Y rotation of player
    yRotationAngle = player.transform.rotation.eulerAngles.y;

    // convert to Quaternion using only the Y rotation
    Quaternion yRotation = Quaternion.Euler(0f, yRotationAngle + 90f, 0f);

    // Apply yRotation
    newValue = yRotation * newValue;

    return newValue;
}    

暫無
暫無

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

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