繁体   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