不能同时旋​​转和移动 - c#

我目前正在Unity 3D中开发FPS射击游戏。我是Unity的新手,我的播放器移动脚本遇到了一些麻烦。个别而言,一切似乎正常,我可以自由旋转和移动播放器,但是当我尝试同时执行两个操作时,播放器似乎锁定并且不会旋转。

有时在地形上跳跃或移动到更高的地面似乎可以解决问题,但是我在禁用重力,没有对撞机且玩家位于地面上方的情况下进行了一些检查,因此问题似乎出在脚本上。我也做了一些调试,并且Rotate()代码确实运行了,只是旋转量似乎没有变化。

这是玩家移动脚本:

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

[RequireComponent(typeof(Rigidbody))]
public class PlayerMov : MonoBehaviour
{
    [SerializeField]
    private Camera cam;
    [SerializeField]
    private float speed = 5f;
    [SerializeField]
    private float looksensitivity = 4f;

    [Header("Camera View Lock:")]
    [SerializeField] //min and max amount for looking up and down (degrees)
    private float lowlock = 70f;
    [SerializeField]
    private float highlock = 85f;

    private Rigidbody rb;
    private float currentrotx; //used later for calculating relative rotation
    public Vector3 velocity;
    public Vector3 rotation; // rotates the player from side to side
    public float camrotation; // rotates the camera up and down
    public float jmpspe = 2000f;

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

    // Update is called once per frame
    void Update()
    {
        CalcMovement();

        CalcRotation();

        Rotate();
    }

    void FixedUpdate()
    {
        Move();
    }

    private void CalcRotation()
    {
        float yrot = Input.GetAxisRaw("Mouse X"); //around x axis
        rotation = new Vector3(0f, yrot, 0f) * looksensitivity;

        float xrot = Input.GetAxisRaw("Mouse Y"); //around y axis
        camrotation = xrot * looksensitivity;
    }

    private void CalcMovement()
    {
        float xmov = Input.GetAxisRaw("Horizontal");
        float zmov = Input.GetAxisRaw("Vertical");

        Vector3 movhor = transform.right * xmov;
        Vector3 movver = transform.forward * zmov;

        velocity = (movhor + movver).normalized * speed;
    }

    void Move()
    {
        //move
        if (velocity != Vector3.zero)
        {
            rb.MovePosition(rb.position + velocity * Time.fixedDeltaTime);
        }

        //jump
        if (Input.GetKeyDown(KeyCode.Space))
        {
           //add double jump limit later!   
            rb.AddForce(0, jmpspe * Time.deltaTime, 0, ForceMode.Impulse);

        }
    }

    void Rotate()
    {
        //looking side to side
        rb.MoveRotation(rb.rotation * Quaternion.Euler(rotation));

       // camera looking up and down
        currentrotx -= camrotation;
        currentrotx = Mathf.Clamp(currentrotx, -lowlock, highlock);
        cam.transform.localEulerAngles = new Vector3(currentrotx, 0, 0);
    }
}

以下是播放器附带的相关组件:

不能同时旋​​转和移动 - c#

(播放器还附加了几个组件,但我在没有它们的情况下进行了测试,但问题仍然存在)

就像我说的我是一个团结的新手,所以我敢肯定我错过了一些小东西,但是我似乎无法将手指放在上面,我已经坚持了一段时间,所以任何帮助都是非常感激。

参考方案

解决了:

看来我遇到的问题是因为我是从笔记本电脑而不是台式机上运行场景,我认为这是为Unity输入构建的。

当回复有时是一个对象有时是一个数组时,如何在使用改造时解析JSON回复? - java

我正在使用Retrofit来获取JSON答复。这是我实施的一部分-@GET("/api/report/list") Observable<Bills> listBill(@Query("employee_id") String employeeID); 而条例草案类是-public static class…

改造正在返回一个空的响应主体 - java

我正在尝试使用Retrofit和Gson解析一些JSON。但是,我得到的响应机构是空的。当我尝试从对象中打印信息时,出现NullPointerException。我确保URL正确,并且我也确保POJO也正确。我正在使用jsonschema2pojo来帮助创建POJO类。这是我要解析的JSON{ "?xml": { "@versi…

json数组,其中in数组返回错误?坏字符串 - javascript

我将json字符串文件解析为python,并且始终返回error。我使用了在线json格式化程序和验证器,它们也返回错误,因此我需要帮助使我的json正确并告诉我错误 [{ "sentence_id": "TR.00001", "sentence": { "text": …

每个文件合并后添加换行 - python

我有很多类似以下内容的JSON文件:例如。1.json{"name": "one", "description": "testDescription...", "comment": ""} test.json{"name"…

Json到php,json_decode返回NULL - php

我正在用PHP进行JSON解析器的一些API,用于存储有关遗产的信息。我在解析时遇到问题,因为它返回的是NULL值而不是数组或对象。简单的JSON代码可以很好地解析,但是可以这样:{"success":true,"totalCount":1,"data":[{"id":99694…