Search Unity

Back centre point of Game Object with rotation

Discussion in 'Scripting' started by Gogin, Oct 31, 2018.

  1. Gogin

    Gogin

    Joined:
    Nov 9, 2013
    Posts:
    60
    Hey all,

    I would like to ask you how to properly get back centre point of GameObject with rotation.

    Code below works fine until I change rotation of parent GameObject, see screenshot below:

    Code (CSharp):
    1.             Vector3 spawnAreaSize = spawnArea.GetComponent<Renderer>().bounds.size;
    2.             float lengthSP = (spawnAreaSize.x) / 2; //Do not spawn unit on the edge of spawn-area (-unitSize.x)
    3.             float x = -lengthSP + spawnAreaPosition.x;
    4.  
     
  2. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    2,865
unityunity