Search Unity

Having issues with RotateAround and over rotation in a 2d project

Discussion in '2D' started by Robert_Hildebrand, May 6, 2020.

  1. Robert_Hildebrand

    Robert_Hildebrand

    Joined:
    Sep 19, 2018
    Posts:
    15
    Hello All,
    I’m having some difficulty with the function RotateAround a specific point and over rotation.I want this to look somewhat smooth so I’m using speed as a function of angle and delta time.

    I’ve got some code to try and stop the rotation when the distance is close but I really want to stop the rotation perfectly and I’m having a heck of a time figuring out exactly how to do that.

    I’ve seen some examples that use lerp, slerp, and quaternions but it’s been I while since I’ve worked with Quaternions and could use some help. What I have now is as follows:


    bool _isRotating = true;
    float _rotationAngle = 180; //degrees
    Vector3 EndingPosition = a RotateAround computation with the full 180 degrees.

    void PerformRotation()
    {
    if (_isRotating && _rotationAngle != 0f)
    {
    float speed = _rotationAngle * Time.deltaTime;
    MyClayTarget.transform.RotateAround(MyHunter.transform.position, Vector3.forward, speed);

    if (Vector3.Distance(MyClayTarget.transform.position, EndingPosition) < 1.0f)
    {
    _isRotating = false;
    _rotationSpeed = 0f;
    }
    }
    }


    Thank you!
    Robert