簡體   English   中英

我想制作一個鼠標外觀腳本,它可以移動我的頭部,然后在某一點上移動我的整個身體。 我想不通

[英]I want to make a mouse look script, that moves my head, then at a point, moves my whole body. I can't figure it out

我想創建一個腳本,它使用我的鼠標控制我的相機,就像一個基本的 MouseLook 腳本。 但是,我想讓相機隨着頭部移動,當頭部到達特定角度時,我想讓整個身體移動……我想不通。 我已經使用 Unity 一年多了,從 MONTHS 開始就試圖完成它。 我想是時候學習更高級的東西了。 任何幫助表示贊賞,謝謝!

可能的解決方案:(我猜在你的項目中移動相機 == 移動頭部)

您可以使用Vector3.Angle ( https://docs.unity3d.com/ScriptReference/Vector3.Angle.html ) 獲得頭部Transform.eulerAngles和身體Transform.eulerAngles之間的相對角度然后,在Update方法中,您可以旋轉身體手動,例如Rigidbody.MoveRotation ( https://docs.unity3d.com/ScriptReference/Rigidbody.MoveRotation.html )。

您還可以調整此旋轉以使其平滑。 (如果您添加一些代碼,我可以為您提供更多幫助)

7 個月后,我回來了!

public GameObject playerHead;
public GameObject character;

void Update()
{
    //check if the head is at a specific angle and if the mouse is moving
    if (playerHead.transform.localRotation.x >= 0.59f && Input.GetAxis("Mouse X") < 0) {
        //rotate the body at the speed of the mouse
        transform.Rotate(new Vector3(0, Input.GetAxis("Mouse X"), 0));
    //repeat
    } else if (playerHead.transform.localRotation.x <= -0.59f && Input.GetAxis("Mouse X") > 0) {
        transform.Rotate(new Vector3(0, Input.GetAxis("Mouse X"), 0));
    }
}

暫無
暫無

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

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