I need to learn how to use sphere casting and looked up the reference, but there are parts I don't understand, like the charcontrol, p1 and p2. Can anyone explain how to use it to set up various ranges?
http://unity3d.com/support/documentation/ScriptReference/Physics.SphereCast.html
The example in the documentation is wrong. It uses a capsule cast not a spherecast. For spherecasts you don't need p1 and p2. p1 would be enough and should be the position where you want to start the raycast.
I'm posting this here in "Understanding Spherecasting" as I have discovered when researching Physics.SphereCast that most people mis-understand spherecasting and want it to do something other than it's intended for. Moreover, the Unity documentation is typically under-descriptive.
I've posted my documentational bug-report, additional information and a descriptive image here: http://theantranch.com/Unity/Unity.html
In a nut-shell:
Spherecasting is designed to cast a "thick ray" by sending a sphere of size (origin, radius) down a ray (origin, direction, length) and returns an array of raycastHits: raycastHit[] (out hitInfo) that collides with the sphere if they are both on the correct layers (layerMask).
might be what some people are looking for
The scripting reference is for a capsulecast but it's very similar. P1 is the center of the sphere. They calculate it as the gameobject's position + the center of the character controller - half the height of the character controller (this should get you basically the center of the 'charactercontroller' component). P2 is for capsulecasting (the height of the capsule), so omit it from your script. Radius is just the radius of the sphere that you want to cast (1, 2, 8, etc.), then distance is how far the sphere will cast, and it will out hitinfo if it hits anything.
Physics.SphereCast(new Vector3(0,0,0), 2.0f, Vector3.forward, hit, Mathf.Infinity);
Would cast a sphere from the origin of the world forward (along the global Z) with radius 2 for infinity and return hitinfo for what it hits.