如何相对于相机移动?

时间:2019-05-26 06:58:35

标签: c# unity3d camera game-engine

我想让我的左操纵杆抬起头来,而不管相机面对的位置如何,因为现在,无论相机指向何处,我总是向北移动

我认为我没有遵循实现此步骤的步骤,因此需要帮助。 相机肯定会出现在奇怪的地方,它会使用正确的模拟物环绕播放器旋转。如果我具有90度的摄像机角度,您的脚本是否仅起作用?

代码在下面;

rel = node1.relationships.get(node2)
rel = node1.relationships.get(node2)

  File "C:\Users\hp\AppData\Local\Programs\Python\Python36\lib\site-packages\neo4jrestclient\client.py", line 2001, in get
    return self.__getattr__(index, tx=tx)
TypeError: __getattr__() got an unexpected keyword argument 'tx'

感谢您的投入!

1 个答案:

答案 0 :(得分:1)

如果您的相机指向奇怪的方向,则可能需要乘以四元数.FromToRotation来修改相机的前向矢量(并可能向左)

[或仅将z分量设为零,如果地面平坦则归一化]

Vector3 forward = Camera.main.transform.forward;
Vector3 left = Camera.main.transform.left;
float vInput = Input.GetAxis("Vertical");
float hInput = Input.GetAxis("Horizontal");
Vector3 playerMove = forward * vInput + left * hInput

原则上,这如下:

   void Movement()
    {
        Vector3 forward = Camera.main.transform.forward;
        Vector3 right = Camera.main.transform.right;

        float moveHorizontal = Input.GetAxis("Horizontal");
        float moveVertical = Input.GetAxis("Vertical");

        Vector3 jump = new Vector3(0, jumpForce, 0);
        Vector3 tempVel = rigid.velocity;

        Vector3 playerMove = forward * moveVertical + right * moveHorizontal;

        tempVel.x = playerMove.x * moveSpeed;
        tempVel.z = playerMove.z * moveSpeed;
        tempVel.y = 0.0f;

        if (Input.GetButtonDown("Jump"))
        {
            rigid.AddForce(jump, ForceMode.Impulse);
        }

        if (moveHorizontal + moveVertical != 0)
        {
            rigid.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(new Vector3(tempVel.x, 0, tempVel.z)), 0.2F);
        }

        rigid.velocity += tempVel;

        rigid.velocity = Vector3.Scale(new Vector3(rigid.velocity.x, rigid.velocity.y, rigid.velocity.z), new Vector3(movefrictionMultiplier, 1.0f, movefrictionMultiplier));
    }