Search Unity

Unable to Rotate object around its center

Discussion in 'Physics' started by ron2468, Jan 13, 2020.

  1. ron2468

    ron2468

    Joined:
    Jan 11, 2020
    Posts:
    3
    Hi all,

    I can't figure out why this layer is not rotating correctly around its center? (see attached picture).

    Here's a snippet of my code:

    void Start()
    {
    centerOfMass = transform.position; //<== get the current position of the RIGHT Layer
    }
    transform.RotateAround( centerOfMass, Vector3.forward, rotationspeed );

    When I press the R button, it's suppose to rotate 90 degrees clockwise, but the final position is offset as u see in the picture. When I click the button a 2nd time (for a total of 180 degrees rotation), it's offset again, and offset again at 270, but does return to normal position at the 4th click (completing the 360 degree rotation).

    It appears the layer is rotating around a point that is NOT its center, right? So it looks like the transform.position does NOT correspond to the center of the Layer object.

    If so, then how do I programmatically obtain the center of mass or center point of an object?

    I'd GREATLY appreciate any help!!

    Ron
     

    Attached Files: