- Home /
Setting any height value when performing a capsule cast is impossible?
Hey everyone!
I noticed here that the capsulecast constructors don't have any other dimension values than radius. Now the radius I need but I also need the height. I want the capsule to match my players collider and using a layer mask I can check if he brushes into something and respond. Now even though I welcome the discussion as to whether that is a correct approach I would request that the focal point of any assistance remains at understanding how I can modify the dimensions of the capsulecast shape or simulate other variables to have it's performance be the same as of that when it is shapechanged.
Thanks in advance!
EDIT 10:54 12/03/2010:
Hmm did I maybe misinterpret the point 1 and point 2 variables ? Can I mold the shape with that? It seems so redundant since there already is a variable for distance and direction. If so then what is the origin point of the cast? I Still need to link that to be the exact center of the casting object or the collision detection will be wrong. (If all else fails I could go for SweepTest but I'd rather not)
EDIT 10:59 12/03/2010:
Here's a code sample of an attempt to glue it onto the controller. Going to test it soon. Hoping that the point variables center align on the origin and fitting it will auto-match for that reason. If not I will notice soon enough. Regardless I will post my resulst here, it may help someone in getting a good capsule cast in C# :)
private bool BrushingRight() { if(Physics.CapsuleCast( controller.bounds.min, controller.bounds.max, controller.radius, Vector3.right)) { return true; }
else
{
return false;
}
}
EDIT 12:53 12/3/2010:
The system as a whole seems to be able to function with isTrigger property on the target collider but that's not something I want to be having in the entire environment. It is also not a great idea to have that many dependancies for me now.
NOTE: The speed of the controller greatly effects the measurements. Still
But why would it function as isTrigger with Physics.Capsulecast? Maybe it just skipping the rigidbody collision changing the range and therefor it does register brushing through it but when I increase the brushrange (range required between character controller capsulrecast and a collider ) there is no difference in the results , I do think that disproves that theory, which leaves me back with, why is isTrigger property making a difference??
FINAL EDIT 13:04 GMT+1 12/4/2010:
I can chop in down into the two only pieces now relevant for me
1: How do I build and see a capsulecast, or can someone explain it clear enough with a construction example and maybe some sort of image or image description? Debug.DrawLine is not really doing the job for me. I want to see what I'm doing with the point 1 and point 2 variables.
2: What is the effect of the isTrigger property on a collider I interact with using RayCast or any other form of such casting? Since they gave me different results I would expect it to have an effect. What could that be?
Answer by skovacs1 · Dec 03, 2010 at 07:16 PM
Wow! This was a clear question until all of the edits. Now it's sort of unclear what you're asking. Also, including the time without a time zone is sort of meaningless as it will be different times in different places.
The question+the first 2 of the edits
Physics.CapsuleCast performs a sweep of a capsule in 3D space and returns true if it hit anything. These are the parameters:
- point1 : The start of the capsule.
- point2 : The end of the capsule.
- radius : The radius of the capsule.
- direction : The direction into which to sweep the capsule.
- hitInfo : If true is returned, hitInfo will contain more information about where the collider was hit (See Also: RaycastHit).
- distance : The length of the sweep
- layerMask : A Layer mask that is used to selectively ignore colliders when casting a capsule.
point1 and point 2 define the height and center of the capsule to sweep and radius defines the radius of the capsule to sweep. These exist because capsule cast can cast a capsule that is not axis-aligned, whereas CharacterController is defined differently because it is axis-aligned.
direction and distance define the sweep of the capsule.
In the linked script reference you provide, they even give you example code which defines a capsule from a character controller's capsule. All you needed to do was change the direction of the cast and the distance that you used in that code rather than write your code sample.
The third edit
Your comment about isTrigger is sort of confusing. Was there a question in there?
"The speed of the controller greatly affects the measurements"...of what? What measurements? If you mean to say that as your CharacterController moves faster, collision detection is less precise or as your CharacterController moves faster you need to Capsulecast further to detect obstacles in advance, then both of those are obvious and well-documented and the note is unnecessary.
Now you're asking about Spherecast? Which is it? What does this have to do with isTrigger? Are you asking if or why or how to deal with your capsulecast or spherecast colliding with objects whose isTrigger property is set? What are you asking here?
The "final" edit
1: How do I build and see a spherecast, or can someone explain it clear enough with a construction example and maybe some sort of image or image description? Debug.DrawLine is not really doing the job for me. I want to see what I'm doing with the point 1 and point 2 variables.
- Again, spherecast or capsulecast? Spherecast doesn't have a point1 or point2.
- I don't know what you mean by "A construction example", but I will explain the makeup of a capsule and what a capuslecast does with it:
I don't have free image hosting or any intention to seek it out, so enjoy ASCII art:
___ / \ | | //This is a sphere of radius r ___/
<> || //This is a cylinder of radius r and height h <>
//A capsule is two spheres and a cylinder __ / \ //One sphere | | | | //The cylinder | | __/ //The other sphere
//Point 1 is the top of one sphere and point 2 to is the bottom of the other //r is the radius of both the spheres and the cylinder //h = distance(p1, p2) - 2 * r
To build your own capsule:
- create two spheres and a cylinder.
- The x and z positions of the spheres and cylinder must be the same.
- The x,y,z scale of the spheres must equal the x,z scale of the cylinder.
- The y position of sphere 1 is the y scale of the cylinder.
- The y position of sphere 2 is the negative y scale of the cylinder.
Point 1 in your custom capsule will be at the y position of sphere 1 + radius. Point 2 in your custom capsule will be at the y position of sphere 2 - radius.
A CapsuleCast sweeps a capsule through space in the direction provided by the distance provided. Essentially, to "visualize it", it's the same as having two capsules located direction*distance away from each other with a box connecting the cylinders of two capsule and cylinders connecting the spheres of the two capsules. The object closest to the start capsule that is inside of the end capsule AND/OR the connecting box + cylinders, but NOT within the starting capsule will be returned as having been hit if the outward faces of the collider faced toward the capsule being swept. Unfortunately, neither Gizmos nor Debug provides the primitives necessary to represent this easily in the editor. You could draw each and every line outlining the contours of the capsule and the cast, (about 800 or so for an accurate representation) and good luck with that.
What you are doing with point1 and point2 is setting the position, orientation and length of the capsule being swept by the CapsuleCast.
From the docs on CapsuleCollider
point1 is the leftmost point of the capsule and then height+2*radius to the right (on the opposite end of the capsule) is point2. The distance between point1 and point2 is the length of the capsule. The direction from one point to the other is the direction of the capsule. The point half-way between point1 and point2 is the center of the capsule.
2: What is the effect of the isTrigger property on a collider I interact with using RayCast or any other form of such casting? Since they gave me different results I would expect it to have an effect. What could that be?
There is no effect on Raycast. isTrigger should not have any effect on raycasting or any form of casting whatsoever. isTrigger will affect collisions and message sending. It is likely that your raycast situation is inconsistent or incorrect in some way or that you are talking about your collisions rather than your raycasts.
If isTrigger is set, Trigger events will be sent whenever a collider and a collider with a rigidbody would collide, whereas if isTrigger is not set, Collision events will be sent, but not for non-kinematic rigidbodies. Additionally, collision detection is also dependent upon the velocity of the rigidbody and its collision detection setting. See here and here for more.
Oh I actually just add the time for myself really :) It helps me cut some corners and say, I spent enough time on this crap it's time for the magic "work-around" solution
$$anonymous$$easurements of the effect of the spherecast were affected. With speed I could go through solids and triggers , without I could not. (most of times anyway). The revision was made I summarized everything into 2 precise questions that are the only things that are relevant for me now.
Thank you for the time and efficiency! $$anonymous$$uch appreciated!
Changed all instances of sphere to capsule cast. I keep mixing up the names out of force of habit for spherecasting. Sorry about all the confusion, you weren't the only one that was confused ^^