Physics.CapsuleCast Help

Hello,

I’ve been using the Physics.Raycast to cast where my mouse position is, relevant to the scene (Camera.main.ScreenPointToRay).

But the Raycast is too precise, and so I want to try and introduce the CapsuleCast, but I am having a few problems trying to replace it.

This is what I am trying to achieve :

125alt text125

Here is my old Raycast:

var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var layerMask = 1 << 14;

if (chooseLocation) {
		layerMask = ~layerMask;
		Physics.Raycast (ray, hit, 900, layerMask);
		Debug.DrawLine (ray.origin, hit.point);
		dummyObj.Translate((Vector3(hit.point.x, dummyObj.position.y, hit.point.z) - dummyObj.position)); // * Time.deltaTime *followSpeed
		currentHit = hit;
		CustomCurser.showOriginal = false;

	}

And I’m just simply trying to convert this to work with the CapsuleCast:

   var ray = Camera.main.ScreenPointToRay (Input.mousePosition); //-hit-
   var layerMask = 1 << 14;
    	
    	if(debugClick){
    		layerMask = ~layerMask;
    		var p1 : Vector3 = transform.position;
    		var p2 : Vector3 = p1;
    		Physics.CapsuleCast(p1, p2, 10, ray.origin, hit, 10);
    		Debug.DrawLine (ray.origin, hit.point);
    	}

I’m not 100% sure on what I’m suppose to do with the p1 and p2 - What I’m trying to get is for a capsule to raycast on down on anything on my scene that the mouse position is over with a radius of 10.

Would appreciate any help with this.

Thanks

Try

Physics.SphereCast (ray, 10, hit, 900, layerMask);