我在这里关注一个教程:https://youtu.be/Sqb-Ue7wpsI?t=3727 并且我目前正在编程第一人称相机,但不幸的是,我不知道该错误被隐藏在哪里,当我按播放时,FPS相机看起来像是醉酒的人的视线,而不是平稳的移动,而Mouse X和Mouse Y可能是根本原因它,但是这里是代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CMovements : MonoBehaviour
{
[SerializeField]
private Transform Playr, Lookr;
[SerializeField]
private bool Invertaxis;
[SerializeField]
private bool Unlockes = true;
[SerializeField]
private float Sensitivities = 8f;
[SerializeField]
private int smeufsteps = 10;
[SerializeField]
private float Smooth_weit = 0.4f;
[SerializeField]
private float rollangles = 0f;
[SerializeField]
private Vector2 defaulteslookleameats = new Vector2(-70f, 80f);
private Vector2 Lookangles;
private Vector2 Currentmauspos;
private Vector2 Smoothmove;
private float Currentrollangles;
private int last_leuk_frames;
[SerializeField]
private float Rollspeed = 3f;
void Start()
{
Cursor.lockState = CursorLockMode.Locked;
}
void Update()
{
Lockunddelockcursor();
Lookaround();
}
void Lockunddelockcursor()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
if(Cursor.lockState == CursorLockMode.Locked)
{
Cursor.lockState = CursorLockMode.None;
}
else
{
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
}
}
void Lookaround()
{
Currentmauspos = new Vector2(Input.GetAxis(Mausexis.MausY),Input.GetAxis(Mausexis.MausX));
Lookangles.x += Currentmauspos.x * Sensitivities * (Invertaxis ? 1f : -1f);
Lookangles.y += Currentmauspos.y * Sensitivities;
Lookangles.x = Mathf.Clamp(Lookangles.x, defaulteslookleameats.x, defaulteslookleameats.y);
Lookr.localRotation = Quaternion.Euler(Lookangles.x,0f,0f);
Playr.localRotation = Quaternion.Euler(0f, Lookangles.y, 0f);
}
}