I'm using a scroll view to store my game character icons (basically an RPG). The movement system for the characters is tile based, but in game hazards could be located anywhere. So I need to detect if a certain tile will interset with a hazard if a character moves into it. To do this I can calculate the corners of the tile using the co-ordinate system of the scroll view. I thought I could turn these into world co-ordinates then query to see if the collider attached to the hazard contains the point (the collider could be rotated so I can't just do the math myself).
When I try to convert the co-ordinates into world co-ordinates though the numbers I get just don't match up. For example, the lower left corner of the tile a character will move into is at (-1250.0, -938.0). If I convert that to world co-ordinates I get (-28.7, -49.8). The actual position for the hazard I'm testing against has a world position of (-8.0, -1.5, 93.4) though and the test tile should be right on top of it.
I'm using code like this to try to get the world co-ordinates:
Vector2 charPosition5 = travellingCharacter.owningGameObject.GetComponent<RectTransform>().transform.TransformPoint(travellingCharacter.GetComponent<RectTransform>().anchorMax); Vector2 charPosition6 = travellingCharacter.GetComponent<RectTransform>().transform.TransformPoint(travellingCharacter.owningGameObject.GetComponent<RectTransform>().anchorMin);
Can someone tell me what values I should be feeding in or what other function I should be using please?