Unity C#相机故障

问题描述

我正在制作FPS游戏,当我直接向左或向右看时,我的Z旋转设置为90,并且我的角色(胶囊)快速旋转。自从我将照相机脚本添加到程序以来,这种情况就一直在发生,所以我认为添加后的任何内容都与它无关。

这是我的“相机运动”代码

beam.io.WritetoTFRecord

这是我胶囊运动的代码

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerCameraController : MonoBehavIoUr
{
    [Serializefield] private float lookSensitivity;
    [Serializefield] private float smoothing;

    private GameObject player;
    private Vector2 smoothedVeLocity;
    private Vector2 currentLookingPos;

    private void Start()
    {
        player = transform.parent.gameObject;
        Cursor.lockState = CursorLockMode.Locked;
        Cursor.visible = true;
    }

    private void Update()
    {
        RotateCamera();
    }

    private void RotateCamera()
    {
        Vector2 inputValues = new Vector2(Input.GetAxisRaw("Mouse X"),Input.GetAxisRaw("Mouse Y"));

        inputValues = Vector2.Scale(inputValues,new Vector2(lookSensitivity * smoothing,lookSensitivity * smoothing));

        smoothedVeLocity.x = Mathf.Lerp(smoothedVeLocity.x,inputValues.x,1f / smoothing);
        smoothedVeLocity.y = Mathf.Lerp(smoothedVeLocity.y,inputValues.y,1f / smoothing);

        currentLookingPos += smoothedVeLocity;

        transform.localRotation = Quaternion.AngleAxis(-currentLookingPos.y,Vector3.right);
        player.transform.localRotation = Quaternion.AngleAxis(currentLookingPos.x,player.transform.up);
    }
}

这也是我的射击程序的代码

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MovementController : MonoBehavIoUr
{
    [Serializefield] private float speed;
    [Serializefield] private float jumpForce;
    [Serializefield] private float jumpRaycastdistance;

    private Rigidbody rb;

    private void Start()
    {
        rb = GetComponent<Rigidbody>();
    }

    private void Update()
    {
        Jump();
    }

    private void FixedUpdate()
    {
        Move();
    }

    private void Move()
    {
        float hAxis = Input.GetAxisRaw("Horizontal");
        float vAxis = Input.GetAxisRaw("Vertical");

        Vector3 movement = new Vector3(hAxis,vAxis) * speed * Time.fixedDeltaTime;

        Vector3 newPosition = rb.position + rb.transform.TransformDirection(movement);

        rb.MovePosition(newPosition);
    }
    private void Jump()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            if (IsGrounded())
            {
                rb.AddForce(0,jumpForce,ForceMode.Impulse);
            }
        }
    }

    private bool IsGrounded()
    {
        return Physics.Raycast(transform.position,Vector3.down,jumpRaycastdistance);
    }
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)