我正在尝试为我的播放器对象(球形)制作相机。假设旋转相机和播放器。但是,当我移动播放器时,它就像疯了似的,因为它是一个球体。我不知道如何解决这个问题。我不确定是否是由于轮换所致。
没事。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraC0ntroller : MonoBehaviour
{
public float RotationSpeed = 1;
public Transform Target, Player;
float mouseX, mouseY;
// Start is called before the first frame update
void Start()
{
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;
}
// Update is called once per frame
void LateUpdate()
{
CamControl();
}
void CamControl()
{
mouseX += Input.GetAxis("MouseX") * RotationSpeed;
mouseY -= Input.GetAxis("MouseY") * RotationSpeed;
mouseY = Mathf.Clamp(mouseY, -35, 60);
transform.LookAt(Target);
Target.rotation = Quaternion.Euler(mouseY, mouseX, 0);
Player.rotation = Quaternion.Euler(0, mouseX, 0);
}
}
我希望它不会开始飞来飞去。