2017-07-14 169 views
0

我有一个简单的脚本附加到统一的球模型。为了控制球,我试图模仿文档提供的示例this。我收到的问题是我的球视觉上旋转的速度是其物理旋转速度的一半。例如:当您进行360度物理旋转时,球会以视觉180度旋转。Unity C#CharacterController脚本

公共类的PlayerController:MonoBehaviour {

public float MoveSpeed; 
public float RotationSpeed; 
CharacterController controller; 

void Start() 
{ 
    controller = GetComponent<CharacterController>(); 
} 

void Update() 
{ 
    transform.Rotate(new Vector3(0, Input.GetAxis("Horizontal") * RotationSpeed, 0)); 
    Vector3 forward = Input.GetAxis("Vertical") * transform.TransformDirection(transform.forward) * MoveSpeed; 

    controller.Move(forward); 
} 

我想做到的是对球对准它的物理控制的旋转而旋转。

+1

您确定需要'transform.TransformDirection(transform.forward)'吗? 'transform.forward'没有做这项工作吗? –

+0

好热的当你解决它。我一直试图通过它不同的论点,我认为这是问题。你想发布这个答案,所以我可以接受它为雅? – Ryan

+0

我无法接受它8分钟,但是当我可以确认它。再次感谢 – Ryan

回答

3

只要摆脱transform.TransformDirection(transform.forward),因为您试图将变换的局部向前向量变换为同一变换的向前向量。

改为使用简单的transform.forward