Posts

Showing posts with the label collider

apply force to objects within an area and other stuff

Bit of a messy example, but it demonstrates a few things in a simple way. 1 - finding the gameobjects that a collider is connected to 2 - finding the rigidbody component of said gameobject 3 - applying a force to rigidbody 4 - optional destroying gameobjects 5 - Oh and the "Physics Overlap Sphere" function. It returns all the colliders within a given spherical volume.   public void physicsSphereMake(Vector3 coord, float radius, float multiply)     {       //get an array of colliders within an overlap sphere that we provide position and radius for            Collider[] hitColliders = Physics.OverlapSphere(coord, radius);         //loop through array         foreach(var hitCollider in hitColliders)         {               //find out the game object   ...