我真的读过了无数的教程,但都没有效果。使用这段代码,我要么激活最后一行,要么激活第二行,分别得到x旋转或y旋转,但我显然希望它们一起工作。
void MouseLook()
{
mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime;
mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime;
xRotation -= mouseY;
xRotation = Mathf.Clamp(xRotation, -60, 10);
transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
transform.Rotate(Vector3.up * mouseX);
}
其中一个似乎总是把另一个抵消掉。这是来自Brackey教程的。我不得不修改一些东西以使其适用,但我显然是那样破坏了代码。请帮帮我!
发布于 2022-01-13 11:43:18
,试试这个东西,
public float mouseSensitivity = 10.0f;
public Transform target;
public float dstFromTarget = 2.0f;
public float yaw;
public float pitch;
public Vector2 pitchMinMax = new Vector2(-50, 85);
public float rotationSmoothTime = 0.02f;
Vector3 rotationSmoothVelocity;
Vector3 currentRotation;
void LateUpdate()
{
MouseLook();
}
void MouseLook()
{
//Mouse Movement
yaw += Input.GetAxis("Mouse X") * mouseSensitivity;
pitch -= Input.GetAxis("Mouse Y") * mouseSensitivity;
// Claemp
pitch = Mathf.Clamp(pitch, pitchMinMax.x, pitchMinMax.y);
// Positioning
transform.eulerAngles = currentRotation;
// Smoothening
currentRotation = Vector3.SmoothDamp(currentRotation, new Vector3(pitch, yaw), ref rotationSmoothVelocity, rotationSmoothTime);
transform.localRotation = Quaternion.Euler(currentRotation.x,currentRotation.y,currentRotation.z);
}
https://stackoverflow.com/questions/70695815
复制相似问题