A position behind a moving gamobject but still inside another gameobject
Hi,
i'm trying to find a random position in 3d world space behind an AI driven character. The problem is, the position have to be inside the boundarys of another gameobject(cube).
What i have so far is the random position inside the whole cube, but not only behind the AI.
public GameObject WaterCube;//the water itself
private BoxCollider Water;//get the size of the water
public static Vector3 Tank;//save the size of the collider here
void Start ()
{
Water = WaterCube.GetComponent<BoxCollider>();
Tank = Water.bounds.size-new Vector3(1,1,1);//decrease the bounds by 1, so nothing would be in the glass
Water.enabled = false;//disable collider because of weird effects might happening
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Glas")
{
if (!turning)
{
//recalculate newGoalPos
newGoalPos = UpdateGoalPos();
}
turning = true;
}
}
Vector3 UpdateGoalPos()
{
goalPos = new Vector3(Random.Range(WaterCube.transform.position.x-Tank.x/2,WaterCube.transform.position.x+Tank.x/2),
Random.Range(WaterCube.transform.position.y-Tank.y/2,WaterCube.transform.position.y+Tank.y/2),
Random.Range(WaterCube.transform.position.z-Tank.z/2,WaterCube.transform.position.z+Tank.z/2));
//Instantiate(WayPoint, goalPos, Quaternion.identity);
return goalPos;
}
I hope you have an idea how i can approach this. Thanks in advance
Comment