我刚刚写了这段代码:
public float sensitivity = 5.0f;
public float smoothing = 2.0f;
Vector2 smoothV;
Vector2 mouseLook;
GameObject character;
// Use this for initialization
void Start () {
character = transform.parent.gameObject;
}
// Update is called once per frame
void Update () {
var mouse = new Vector2(Input.GetAxisRaw("Mouse X"), Input.GetAxisRaw("Mouse Y"));
mouse = Vector2.Scale(mouse, new Vector2(sensitivity * smoothing, sensitivity * smoothing));
smoothV.x = Mathf.Lerp(smoothV.x, mouse.x, 1f / smoothing);
smoothV.y = Mathf.Lerp(smoothV.y, mouse.y, 1f / smoothing);
mouseLook += smoothV;
transform.localRotation = Quaternion.AngleAxis(-mouseLook.y, Vector3.right);
character.transform.localRotation = Quaternion.AngleAxis(mouseLook.x, character.transform.up);
}
除了在水平轴上移动相机外,它的工作原理非常好。我认为Gameobject的初始化是错误的吗?
提前致谢!