Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Dr. Watson · Oct 18, 2010 at 02:48 AM · collisionphysicscapsulecast

How to keep CapsuleCast() from sweeping?

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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by Jessy · Oct 18, 2010 at 03:06 AM

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

Comment
Add comment · Show 11 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Dr. Watson · Oct 18, 2010 at 03:29 AM 0
Share

The part I don't get is the start and end point??? I would think you would have an origin and then sweep it in any direction. I can set the start and end points to get the result I'm looking for but I just can't wrap my $$anonymous$$d around why you would need to set a start and end point and then sweep it?

avatar image Jessy · Oct 18, 2010 at 03:34 AM 0
Share

You need to define a capsule before you can sweep/cast it. point1 and point2 are just the ends of the capsule. That is, right in the middle of the hemispheres on the ends, on the edge.

avatar image Dr. Watson · Oct 18, 2010 at 04:05 AM 0
Share

Yea I get that but I guess I don't get why you would do that because the points will change the second it sweeps right?

avatar image Dr. Watson · Oct 18, 2010 at 04:06 AM 0
Share

So what's the point of defining the start/end points?

avatar image Jessy · Oct 18, 2010 at 05:03 AM 0
Share

I don't think you do get it; you're asking what they are, when they are essential parts in defining a capsule. You define a capsule, with two points and a radius. Then you send it in a direction. It's basically the same thing as if you had a capsule mesh and used rigidbody.AddForce on it.

Show more comments
avatar image
4

Answer by guavaman · Oct 06, 2012 at 05:15 PM

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 http://docs.unity3d.com/Documentation/ScriptReference/Physics.CheckCapsule.html 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. http://docs.unity3d.com/Documentation/ScriptReference/Gizmos.DrawSphere.html

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
     }
 }

}

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

1 Person is following this question.

avatar image

Related Questions

Test stationary capsule against colliders in scene. 2 Answers

Keep Horizontal Momentum after Jump 2 Answers

How to stop sphere from clipping through cube edges aside from lowering Time.FixedDeltaTime? 1 Answer

Collision.impulse = 0 in OnCollisionStay Kinematic Static collision pair after Update 0 Answers

Player's Rigidbody slides up terrain walls 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges