【问题标题】: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我想制作一个鼠标外观脚本,它移动我的头,然后在某个点移动我的整个身体。我想不通
【发布时间】:2019-08-09 23:13:59
【问题描述】:

我想创建一个脚本,它使用鼠标控制我的相机,就像一个基本的 MouseLook 脚本。但是,我想让相机随着头部移动,当头部到达特定角度时,我希望整个身体都移动……我想不通。我已经使用 Unity 一年多了,自 MONTHS 以来一直在尝试完成这项工作。我认为是时候学习一些更高级的东西了。任何帮助表示赞赏,谢谢!

【问题讨论】:

  • 你能展示一些代码让我们看看你到目前为止做了什么吗?

标签: c# unity3d controller mouse


【解决方案1】:

可能的解决方案: (我猜移动相机 == 在你的项目中移动头部)

您可以使用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)。

您也可以调整这种旋转以使其顺利进行。 (如果你添加一些代码,我可以帮助你更多)

【讨论】:

    【解决方案2】:

    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));
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-17
      • 1970-01-01
      • 2021-04-02
      • 1970-01-01
      • 2021-08-28
      • 2021-11-22
      • 2023-02-21
      相关资源
      最近更新 更多