Thursday, September 24, 2026
spot_img

The way to rotate a dad or mum object whereas rotating a toddler object to a sure angle utilizing coroutines


I’ve a semicircle like recreation object which I made by placing two arcs in an empty recreation object (SCircle) and rotating the 15° (for left arc) and -15° (for proper arc) as seen under.

The way to rotate a dad or mum object whereas rotating a toddler object to a sure angle utilizing coroutines

SCircle has an Orientation enum with two valuesLeft (rotates SCircle to 45°) and Proper (rotates SCircle to -45°) as seen within the picture under.

enter image description here

I exploit the next coroutine to maneuver SCircle between orientations.

IEnumerator RotateLeftOrRight(Vector3 byAngles, float inTime)
{
    Quaternion fromAngle = gameObject.remodel.rotation ;
    Quaternion toAngle = Quaternion.Euler (remodel.eulerAngles);


    if (circOrientation == Orientation.Left) {
        toAngle = Quaternion.Euler (gameObject.remodel.eulerAngles - byAngles);
        circOrientation = Orientation.Proper;

    }
    else if (circOrientation == Orientation.Proper) {

        toAngle = Quaternion.Euler (gameObject.remodel.eulerAngles + byAngles);
        circOrientation = Orientation.Left;
    }


    for(float t = 0f ; t <= 1f ; t += Time.deltaTime/inTime)
    {
        gameObject.remodel.rotation = Quaternion.Lerp(fromAngle, toAngle, t) ;
        yield return null ;

        gameObject.remodel.rotation = Quaternion.Lerp(fromAngle, toAngle, 1);
    }

}

I additionally used a really related coroutine to maneuver the person arcs by 30° (in reverse instructions) from say, Orientation Left, as seen under:

enter image description here

Since SCircle Coroutine is activated by a mouse click on, I’ve the case the place the person arcs coroutine is run and earlier than it’s full the dad or mum SCircle coroutine can also be run. On this case the arcs find yourself shifting from Left to A, which isn’t the conduct I would like. I’d need the conduct of them ending up at B when shifting from the Left. Likewise, from B, when the SCircle coroutine is run whereas the arcs coroutine is in progress the orientation will return to the Left.

Please be aware that the blue arrow represents the motion of the left Arc, the purple represents the correct Arc and the black represents motion of SCircle – the dad or mum object.

How can I obtain the conduct from Left to B and from B again to Left?

enter image description here

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisement -spot_img

Latest Articles