x


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

more ▼

asked Jun 30 '11 at 03:54 PM

oliver-jones gravatar image

oliver-jones
2.5k 205 225 254

All I want is to make the raycasts width a bit wider.

Jul 01 '11 at 11:49 AM oliver-jones
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Try

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

more ▼

answered Jun 30 '11 at 03:58 PM

jonas echterhoff gravatar image

jonas echterhoff ♦♦
9.8k 7 23 104

is there a way I can do a Debug.DrawLine for the whole sphere?

Jun 30 '11 at 04:00 PM oliver-jones

This doesn't seem to be doing the job

Jun 30 '11 at 05:02 PM oliver-jones

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).

Jul 01 '11 at 12:07 PM Waz

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).

Jul 01 '11 at 12:59 PM PrimeDerektive

@Derek Traver - that is exactly what I want, how would i go about doing that?

Jul 01 '11 at 01:44 PM oliver-jones
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1877
x1531
x69
x38

asked: Jun 30 '11 at 03:54 PM

Seen: 1738 times

Last Updated: Jul 02 '11 at 11:09 AM