(Unity2D) Персонаж дергается при повороте

у меня появилась такая проблема - персонаж дергается когда рука находится на границе поворота. Мой персонаж свободно двигается в пространстве. Рука и тело это разные объекты. Рука закреплена на теле и может вращаться на 360 градусов. Я сделал поворот персонажа при выворачивании руки, дабы тело развернулось в сторону руки.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AstroManeuver : MonoBehaviour{
[SerializeField] AstroScript astroScr;

[Header("Maneuver variables")]
internal Vector2 mousePos;

[Header("Other ref")]
[SerializeField] internal Transform handRot;
[SerializeField] internal Transform secondHandRot;
[SerializeField] internal Transform firePointRot;

private void Start()
{
    print("Astro Man");
}

private void Update()
{
    mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition); //Считывание координат мыши
}

private void FixedUpdate()
{
    if (!astroScr.astroAnimScr.bodyUp && !astroScr.astroAnimScr.bodyDown)
    {
        //Разворот персонажа в зависимости от расположения руки
        if (astroScr.astroHandsChScr.angle < 180f && astroScr.astroHandsChScr.angle > 0f)
        {
            transform.localScale = new Vector3(1, 1, 1);
            handRot.localScale = new Vector3(1, 1, 1);
            secondHandRot.localScale = new Vector3(1, 1, 1);
            firePointRot.localRotation = Quaternion.Euler(0, 0, 90);
        }
        else if (astroScr.astroHandsChScr.angle > -180f && astroScr.astroHandsChScr.angle < 0f)
        {
            transform.localScale = new Vector3(-1, 1, 1);
            transform.localScale = Vector3.Lerp(transform.localScale, new Vector3(-1, 1, 1), Time.deltaTime);
            handRot.localScale = new Vector3(-1, -1, 1);
            secondHandRot.localScale = new Vector3(-1, -1, -1);
            firePointRot.localRotation = Quaternion.Euler(0, 180, 90);
        }
    }
}

Но дело в том, что при таком способе разворота на границах, персонаж начинает дергаться. То есть когда когда персонаж дергается когда рука смотрит ровно вверх или ровно вниз

astroScr.astroHandsChScr.angle - это угол поворота руки


Ответы (0 шт):