Hey guys. I have an enum of ‘Locations’, here:
public enum Location
{
TopRight,
TopLeft,
BottomLeft,
BottomRight,
Central,
CenterLeft,
CenterRight,
CenterTop,
CenterBottom
}
Now I have a transform with a positionA, and it is rooted to positionB (Also, the game doesn’t worry about the Y axis, only X/Z. 2D game). I am trying to figure out which ‘location’ the position will fall in to. I can work this out very simply by doing a with X/Y checks to see where the point lies, but this does not take into consideration the rotation of the parent and because I am using world positions, my results get all whack.
The reason I can’t stick to only using local locations is because the solution should be able to work on the positions of the childrens children, etc. So that is, Point X could be a a child of point Y, which is (finally) a child of point Z, but the ‘location’ of Point X should be relative to the root objects position, point Z.
An illustration:
TopRight, green
TopLeft,red
BottomLeft,purple
BottomRight, blue
Central, white
CenterLeft, black
CenterRight, pink
CenterTop,yellow
CenterBottom, grey
Currently, what I am doing is using the angle between (positionA’s worldpos - positionB’s worldpos) and (positionB’s forward vector). This returns an angle between 0 > 180 (I work out the angles polarity by doing a cross product between positionA’s world pos and positionB’s forward vector). I then use this angle to determine which Location i should slot the object in to. But then I get a distributions that is more like this, and not what I am after: