【问题标题】:Rotate a player on sphere using joystick使用操纵杆在球体上旋转玩家
【发布时间】:2018-10-17 06:11:26
【问题描述】:

我想在一个球体上统一旋转我的播放器并使用此代码旋转它,但它适用于球体上的某些位置,有人可以帮助解决这个问题吗?或click 观看问题视频的链接。

using UnityEngine;
using UnityStandardAssets.CrossPlatformInput;


public class Follow_guide_pos : MonoBehaviour {

     private Vector3 input;

     void Update () {
    //rotation of player input
    input = new Vector3(CrossPlatformInputManager.GetAxisRaw("Horizontal_rot"),CrossPlatformInputManager.GetAxisRaw("Vertical_rot"),0);
    }

    void FixedUpdate(){
    //rotation of player output
    transform.LookAt(transform.position+input,transform.up);


   }
}

Link to the video 是问题的视频。 0:03-0:07 飞机正确旋转 但是在将其沿其他方向移动后,它会在不同的轴上旋转或不像以前那样旋转。

【问题讨论】:

    标签: c# unity3d


    【解决方案1】:

    LookAt 函数采用“向上”方向来帮助将对象对齐到所需的方向。当您在球体周围移动时,您的车辆的真正“向上”正在发生变化。因此,您需要更改 LookAt 中的“向上”向量以匹配您车辆所需的“向上”。

    【讨论】:

      猜你喜欢
      • 2021-07-06
      • 1970-01-01
      • 2021-01-10
      • 2019-07-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多