【问题标题】:How can I prevent my gameobject from rotating all the time when trying to move it如何防止我的游戏对象在尝试移动它时一直旋转
【发布时间】:2017-08-08 13:58:10
【问题描述】:

所以我有一个通过操纵杆移动的游戏对象(我的玩家)。如果没有下面的旋转代码,我的玩家移动得很好而且很流畅,但是在我把旋转代码放在下面之后,当我尝试移动它时,游戏对象会一直旋转(360 度)。

我的目标是在玩家转动时围绕特定角度旋转玩家。

void Update()
{
    // move
    _rigidbody.MovePosition(transform.position + (transform.forward * leftController.GetTouchPosition.y * Time.deltaTime * speedMovements) +
        (transform.right * leftController.GetTouchPosition.x * Time.deltaTime * speedMovements) );

    //rotate 
    double rad = Mathf.Atan2(leftController.GetTouchPosition.y, leftController.GetTouchPosition.x); // In radians
    double deg = rad * (180 / System.Math.PI);
    transform.RotateAround(transform.position, Vector3.up * Time.deltaTime, (float) deg);
}

【问题讨论】:

  • 在你的最后一行代码中。 transform.RotateAround(transform.position, Vector3.up , Time.deltaTime * (float) deg);不应该更像这样吗?
  • @EmreE 好一点。 now.but 现在的问题是,例如,当我的操纵杆位于左上角时,我的玩家会在该位置移动,并且在此期间,由于每一帧,它都会一直旋转。我想要的是我正常行走到一个位置,每个角度应该只有一个旋转。当我移动时它会旋转 360 度...

标签: c# unity3d rotation angle


【解决方案1】:

如果我错了,请纠正我,但如果我的问题正确,我认为你使用了错误的功能。

对我来说,RotateAround 会更好,例如行星轨道(永动机)

如果您只想在给定方向旋转播放器并在完成后停止,您应该尝试以下功能:

  • Transform.LookAt
  • 四元数.LookRotation
  • 四元数.RotateTowards
  • 四元数.Slerp

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-01-23
    • 1970-01-01
    • 2017-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多