- Home /
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 :
125125
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
All I want is to make the raycasts width a bit wider.
Answer by jonas-echterhoff · Jun 30, 2011 at 03:58 PM
Try
Physics.SphereCast (ray, 10, hit, 900, layerMask);
is there a way I can do a Debug.DrawLine for the whole sphere?
It should work. Note that this is a replacement for your original Raycast, not your capsule cast. Note that the shape of a SphereCast is a capsule (obvious when you imagine it).
Note that a SphereCast is shaped like a long, sideways capsule... but a CapsuleCast is shaped like a long "bar" of sorts with upright capsules on the "ends", which might be what he really want (like if his trying to do a check if a capsule collider will fit in a space, SphereCast is probably not what he wants).
@Derek Traver - that is exactly what I want, how would i go about doing that?
Your answer
Follow this Question
Related Questions
Why does CapsuleCast appear in the wrong place? 0 Answers
The CapsuleCast is broken. 0 Answers
Physics.SphereCastAll with triggers 1 Answer
AddForce to a point of a GameObject, not the center 1 Answer
HOW DO I USE RAYCASTHIT 2D???? 1 Answer