I am making a game where you play as a ball bouncing around randomly generated platforms. When one platform becomes invisible a new on will be Instantiated to replace it at a random point within the camera’s view. This works but often they end up inside the player, sending them flying off randomly. Is there a way to make sure they do not appear anywhere within the player’s collider? This is the code I am using. Also, if anyone knows how to only make them appear on the edge of the camera rectangle opposite the side the previous platform exited on, that would be helpful.
ray1=Camera.main.ViewportPointToRay(Vector3(1,1,0));
ray2=Camera.main.ViewportPointToRay(Vector3(0,0,0));
var hit : RaycastHit;
var hit2 : RaycastHit;
if(Physics.Raycast(ray1,hit)){
maxX=hit.point.x;
minY=hit.point.y;
}
if(Physics.Raycast(ray2,hit2)){
minX=hit2.point.x;
maxY=hit2.point.y;
}
Rand1=Random.Range(minX,maxX);
Rand2=Random.Range(minY,maxY);
var platPos=Vector3(Rand1,Rand2,transform.position.z);
var newPlat=Instantiate(platform,platPos,rot);