Unity 2d Вращение машины сверху вниз с помощью клавиатуры - PullRequest
0 голосов
/ 14 июля 2020

в моей двумерной игре сверху вниз я установил движение и вращение машины, но она вращается очень странно, и вращение нарушается, когда другой объект (как враг) сталкивается с ним и слегка перемещает его.

Итак в первую очередь я хочу сделать вращение более плавным.

Вот что я пробовал:

 private void Move()
{
    //Control of velocity of the car
    float HorizontalcontrolThrow = CrossPlatformInputManager.GetAxis("Horizontal"); // Value between -1 to 1
    float VerticalcontrolThrow = CrossPlatformInputManager.GetAxis("Vertical"); // Value between -1 to 1

    if (HorizontalcontrolThrow != 0 || VerticalcontrolThrow != 0)
    {
        Vector2 playerVelocity = new Vector2(HorizontalcontrolThrow , VerticalcontrolThrow );
        myRigidbody.velocity = playerVelocity * driveSpeed;

        //Direction of the car
        Vector2 direction = new Vector2(HorizontalcontrolThrow, VerticalcontrolThrow);
        float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;


        //myRigidbody.rotation = angle;

        //Quaternion rotation = Quaternion.Euler(0, angle, 0);
        Quaternion rotation = Quaternion.AngleAxis(angle, Vector3.forward);
        transform.rotation = Quaternion.Slerp(transform.rotation, rotation, driveSpeed * Time.deltaTime);
    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...