How can i find the world position of collider?
So I'm trying to create collision without the onCollisionEnter2D function.
The way I'm doing so is with calculating the distance between the player and my door.
I've tryed many things, and non worked...
Here is an example of what I'm trying to do (After collecting all coins, the door is moving, but the door's boxCollider is staying in place, I'm trying to calculate the distance between the player and the door's boxCollider, the first problem was that the boxColider was on local position of the door, i overcome this with TransformPoint, but now the problem is that it shows me the position of the box collider on the exact position of the door object, which is not true since the door moved and the collider stayed, this is my code :
public GameObject door; //Door reference.
public float distancePlayerDoor; //Check distance between player and door.
public BoxCollider doorMove; //Reference doors collider.
void Win(){
//Winning condition, open door, exit, finish menu.
Vector3 temp = door.transform.position; //Reference door position.
temp.x = -181.0f; //Move door in X.
temp.y = 10.0f; //Move door in Y. (Not needed).
temp.z = -185.0f; //Move door in Z. (Not needed).
door.transform.position = temp; //Fix door position.
doorMove.isTrigger = true; //Turn on the doors trigger for collision.
Vector3 temp2 = doorMove.center; //Reference door box collider left for collision.
temp2.x = -1.0f; //Leave the doors collider at its place.
doorMove.center = temp2; //Fix the door box collider position.
Vector3 temp4 = doorMove.transform.TransformPoint (Vector3.zero);
temp4.y = 0.0f;
distancePlayerDoor = Mathf.Sqrt (temp4.x * temp4.x + temp4.z * temp4.z);
Debug.Log (temp4);
// Vector3 temp3 = doorMove.transform.position-player.transform.position; //Reference the door vectore position minus player vector position. // temp3.y = 0.0f; //Reset the y=0, because if: Y < 0 < Y then Y = 1 or Y = -1, the distance will always grow up or down. // // distancePlayerDoor = Mathf.Sqrt (temp3.x temp3.x + temp3.z temp3.z); //Square the door vectore and the player vectore to get the new vectore of distance.
if (distancePlayerDoor < 10.0f) { //Check if player is on the door.
Destroy (game); //Destroy all the game elements.
Destroy (Scene1); //Destroy all the Scene elements.
Destroy (loseBG); //Destroy the losing menu.
} //Check if player is collided with the door.
} //Create the wining aspects of opening the door and checking that player got to the exit.