Здравствуйте, есть 2D игра, с 3D лабиринтом шаром, при кручении лабиринта свайпом, шар ведет себя очень плохо, отпрыгивает от стен. Как это можно исправить?
Скрипт лабиринта:
{
[SerializeField]
float speedRotation = 5.0f;
Rigidbody rb;
Vector2 startDirection;
Quaternion startRotation;
void Start()
{
rb = GetComponent<Rigidbody>();
rb.isKinematic = true;
rb.collisionDetectionMode = CollisionDetectionMode.ContinuousDynamic;
}
void Update()
{
if (Input.touchCount > 0)
{
Touch touch = Input.GetTouch(0);
switch (touch.phase)
{
case TouchPhase.Began:
startRotation = transform.rotation;
startDirection = GetTouchDirection(touch);
break;
case TouchPhase.Moved:
float angle = Vector2.SignedAngle(startDirection, GetTouchDirection(touch));
Quaternion needRotation = startRotation * Quaternion.AngleAxis(angle, Vector2.down);
rb.MoveRotation(Quaternion.Lerp(rb.rotation, needRotation, Time.deltaTime * speedRotation));
break;
}
}
}
Vector2 halfScreenSize => new Vector2(Screen.width / 2.0f, Screen.height / 2.0f);
Vector2 GetTouchDirection(Touch touch) => touch.position - halfScreenSize;
}