Detect if player is standing within a circular boundary on the terrain

Hi all,

Could someone explain conceptually how a script would define an invisible circular boundary on a terrain and determine if the player were standing within that circle? I am also concerned with how the varying elevation of the terrain would affect the accuracy of the detection.

Thanks!

I can think of two ways. Either a trigger, or bounds.

You can place an empty gameobject (perhaps with a colored Editor Icon “pill” to make it visible in editor), and then use the Vector3.Distance() function to see if you the player is within range.

Perhaps some code like this on the actual object, placed at the center of the spherical area you care about.

public Transform player;
float range = 10.0f;

// ....

if (Vector3.Distance( player.position, transform.position) <= range)
{
// set some flag saying the player is within range
}
1 Like