15.4 C
New York
Tuesday, May 6, 2025

The way to rotate a mother or father object whereas rotating a toddler object to a sure angle utilizing coroutines


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

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 comparable 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 mother or father SCircle coroutine can 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 pink represents the correct Arc and the black represents motion of SCircle – the mother or father 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

Latest Articles