i need a think raycast that will return all the objects on it, so i used CapsuleCastAll.
the problem is i dont really understand how does it works?
if im giving it 2 Vectors, why do i need to type the direction and the distance? i mean 2 points + radius makes the capsule… so what the direction is and the distance? its very unclear…
also i cant really see what im doing because thers no debug version for it >.<
The direction and distance is where you want the capsule to move to before it casts. The example in the docs explains this really well - suppose you have a player that uses a capsule collider and you want to figure out if the player will collider if you move a step in a direction. What you would do is use the first and second point and radius to set up the capsule at the player position, and then use the direction and distance to move the capsule a unit in the direction you want to cast.
What your code will do is:
Create a capsule that stretches from the transform position to 5 units above the transform position
That’s because your code hasn’t changed at all. The fourth and fifth arguments are still Vector3.up and 5, which means it’s still going to move it up 5 units. Try setting your distance to 0 instead of 5.
Yeah, it’s hard to debug without a visual guide to what it’s doing. I tried to use one in my own project a while ago and eventually just gave up and used a capsule collider set as a trigger to track objects that came inside.
You might also want to take a look at RaycastAll.
yeah the main reason i dont use RaycastAll is because its not thick and i want to see if the player is on the gameObject…
it works sometimes when i put it on distance (3) and i jump. but when i put it on distance (0) it does not work…
As said, I ended up using a trigger capsule collider.
If you absolutely must use CapsuleCastAll, then all I can tell you is to mess around with the distance variables with a bunch of colliders and see what happens.
I know it’s a very old thread but in case where some people have the same problem (like I had), I recommend you to trick by using Physics.SphereCastAll. As if you create the first sphere of the capsule and move it to the second point of the capsule. If I’m not wrong, the result should be the same. I tried that and it seems to work.
The following code will simulate a capsule as you defined in the Capsule Collider or in CharacterController :