Legacy Documentation: Version 4.5.0

Script language:

  • JS
  • C#
  • Boo
Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

Physics.OverlapSphere

static function OverlapSphere(position: Vector3, radius: float, layerMask: int = AllLayers): Collider[];

Description

Returns an array with all colliders touching or inside the sphere.

NOTE: Currently this only checks against the bounding volumes of the colliders not against the actual colliders.

	// Call a damage function on all objects caught in the
	// radius of an explosion.
	function ExplosionDamage(center: Vector3, radius: float) {
		var hitColliders = Physics.OverlapSphere(center, radius);
		
		for (var i = 0; i < hitColliders.Length; i++) {
			hitColliders[i].SendMessage("AddDamage");
		}
	}