리스폰 가능한 포지션 가져오기(방해물 영역제외)
게임을 만들다보면 게임 장르특성에 따라 다르긴하지만 .
리스폰영역에대한 고민을 할때 구현했던 코드들이다.
기본적으로 겹쳐서 생성하면안되는 로직으로 처리를 했고 distance를 기반으로 해당 위치를 제외하고 리스폰 영역을 구하도록 작업했다.
public Vector3 GetNotObstaclePosition(List<GameObject> _obstacle)
{
Vector3 returnValue = Vector3.zero;
bool flag = false;
do
{
returnValue = this.GetIntPosition(Random.insideUnitSphere * 100f);
returnValue.y = 0f;
if(false == Utill.Instance.CheckMapPosition(returnValue, 0.5f)){
flag = true;
}
else{
flag = false;
for (int i = 0; i < _obstacle.Count; i++)
{
Vector3 pos = _obstacle[i].transform.position;
float distance =Vector3.Distance(returnValue, pos);
//if (distance < 5f)
if (distance < 5f)
{
flag = true;
i = _obstacle.Count;
}
}
}
} while (flag);
return returnValue;
}
public Vector3 GetRespawnPosition(){
Vector3 returnValue = Vector3.zero;
List<GameObject> obstacleList = new List<GameObject>();
List<UnitBase> unitList = UnitManager.Instance.GetUnitList();
for(int i = 0; i < unitList.Count;i++){
obstacleList.Add(unitList[i].gameObject);
}
do{
Vector3 createPosition = InfluenceManager.Instance.GetNotObstaclePosition(obstacleList);
returnValue = new Vector3(createPosition.x ,0.6627319f,createPosition.z);
}while(false == Utill.Instance.CheckMapPosition(returnValue, 0.5f));
return returnValue;
}
★★☆☆☆
반응형
댓글