简体   繁体   English

InControl-如何流畅地旋转播放器

[英]InControl - How to Rotate Player Smoothly

I'm using the InControl input manager for my project. 我正在为我的项目使用InControl输入管理器 I'm using input from the right stick to rotate my player object, but I want the player to be rotated smoothly rather than instantaneously. 我正在使用来自右摇杆的输入来旋转播放器对象,但是我希望播放器能够平稳地旋转而不是瞬时旋转。

Here's my current code: 这是我当前的代码:

void FixedUpdate()
{
    var device = InputManager.ActiveDevice;

    MoveThePlayer(device.LeftStick.X, device.LeftStick.Y);
    RotateThePlayer(device.RightStick.X, device.RightStick.Y);
}


void MoveThePlayer(float movex, float movey)
{
    body.velocity = new Vector2(movex * speed, movey * speed);
}

void RotateThePlayer(float movex, float movey)
{
    float heading = Mathf.Atan2(movey, movex);
    transform.rotation = Quaternion.Euler(0f, 0f, heading * Mathf.Rad2Deg);
}

Lerps are your friend. 狼疮是你的朋友。

transform.Rotate() your player towards the angle you want by using Time.deltaTime 通过使用Time.deltaTime向您想要的角度transform.Rotate()播放器

Example: 例:

transform.Rotate(0, 0, (angleIWantToBeAt - transform.eulerAngles.z) * Time.deltaTime * speedMultiplier)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM