I want to do a CapsuleCast up/down/left/right of my character but I don't need to sweep it in a direction...so do I use Vector3.Zero for that parameter? Can anybody give me an example of how to do this??? Thanks.
Not sweeping doesn't make any sense; that's what casting is. What don't you understand about the example in the docs? All you'd need to change about it is to switch out transform.forward, and instead use transform.up, -transform.up, -transform.right, and transform.right.
Edit: Here's an "illustration" of what point1 and point2 are, on the capsule with parentheses for endcaps:
point1--->(____)<---point2
I want to do a CapsuleCast up/down/left/right of my character but I don’t need to sweep it in a direction…so do I use Vector3.Zero for that parameter?
It sounds like you might want to use Physics.CheckCapsule Unity - Scripting API: Physics.CheckCapsule This will tell you if anything collides anywhere inside a stationary capsule volume. You could combine this with a Physics.CapsuleCast to cover both the starting position and a cast in a direction, but based on your usage of scaling, it doesn’t sound like you really need a sweep test, just the volume test of Physics.CheckCapsule.
A note about capsule cast:
There is a lot of confusion about how CapsuleCast works because we expect (myself included) CapsuleCast to do something its not designed to. Capsule casting does not just project a solid volume from start to finish and detect any collisions in any direction in its swept volume. Instead, it’s like casting a ray. It only hits if the collider it intersects has a face with normal toward the ray origin. This probably answers all the weird cases of “why doesn’t capsule cast collide when…”
so I can’t tell if I’m getting what I want.
Use gizmos to visualize it. Just make a couple of spheres at the start/end of the capsule and and again at the final position of the cast. Unity - Scripting API: Gizmos.DrawSphere
Here is a little test script you can pop onto a gameobject that will let you see a capsule and move it around to see where it collides. It updates in the editor. If you put it near a wall, you’ll notice it turns red until you move the origin spheres slightly into the wall, then it turns back white (no hit).
using UnityEngine;
using System.Collections;
[ExecuteInEditMode]
public class Capcasttest : MonoBehaviour {
public enum Mode { CapsuleCast = 0, CheckCapsule = 1 };
public Mode mode = Mode.CapsuleCast;
public Vector3 height = new Vector3(0, 2.0f, 0);
public float radius = 1.0f;
public float dist = 3.0f;
private Vector3 vOffset;
private Vector3 dir;
private bool hit;
void Awake() {
vOffset = new Vector3(0, radius, 0);
}
void Update () {
dir = transform.forward;
Vector3 botSpherePos = transform.position + vOffset;
Vector3 topSpherePos = botSpherePos + height;
if(mode == Mode.CapsuleCast) {
hit = Physics.CapsuleCast(botSpherePos, topSpherePos, radius, dir, dist);
// Draw lines
Color lineColor = Color.white;
if(hit) lineColor = Color.red;
Debug.DrawLine(botSpherePos, botSpherePos + (dir * dist), lineColor);
Debug.DrawLine(topSpherePos, topSpherePos + (dir * dist), lineColor);
} else
hit = Physics.CheckCapsule(botSpherePos, topSpherePos, radius);
}
void OnDrawGizmos() {
Vector3 botSpherePos = transform.position + vOffset;
Vector3 topSpherePos = botSpherePos + height;
// Draw spheres
if(hit) Gizmos.color = Color.red;
Gizmos.DrawSphere(botSpherePos, radius); // draw origin top sphere
Gizmos.DrawSphere(topSpherePos, radius); // draw origin bottom sphere
if(mode == Mode.CapsuleCast) {
Gizmos.DrawWireSphere(botSpherePos + (dir * dist), radius); // draw swept bottom sphere
Gizmos.DrawWireSphere(topSpherePos + (dir * dist), radius); // draw swept top sphere
}
}
}