- Home /
Spherecast/Capsulecast bug/glitch
I am trying to make my own Character Controller. I don't mean using the Unity Character Controller component, I'm attempting to make my own from scratch as the Unity one just isn't that great. I researched for a couple of days to see if anyone else has attempted to create their own character controller (which not many people have apparently). I was sure that using raycasts was not the right approach as they are just a line. Eventually I discovered Spherecast/Capsulecasts which (seemed) like it was the solution. All was going well, I managed to get my test capsule to stick to the ground and go up/down slopes. Then I discovered the bug with both types of casts. If a collider is near the origin/start point for either type of cast, then it will not register a hit, at all. So I set out looking for answers and saw that people had been complaining about this as long as 3 years ago. I couldn't find a solution or an explanation as to why it does this, so I presume it must be a bug. There is 1 issue reported in the issue tracker which had 0 votes until I just voted for it. If anyone could help me out in any way, I would appreciate it!!
Answer by whydoidoit · Mar 11, 2014 at 05:46 PM
So if you start a raycast from within a collider it will not register - this is desirable behaviour.
You can check a particular area with Physics.OverlapSphere, you can start your spherecast "back a bit" if there's a danger that you are colliding with something immediately (normally ignoring the player's collider layer so that this is possible). You can also reverse cast back towards the player, which is very useful for camera controllers.
Finally you could also consider Rigidbody.SweepTest
Hi thanks for the quick reply! I understand that you would not want a cast to register the collider that is attached to the game object it is being fired from, but I have no collider attached to my capsule. I am effectively trying to make my own collider, which I know is 100% possible without this bug/glitch/whatever it may be. I am going to throw an image together to demonstrate what I mean more clearly.
But your raycast is probably starting inside the thing that you are hitting right? I'm not talking about the player's collider. So as I say. Start the whole cast from further back in the opposite direction.
I understand what you are suggesting to do. But unfortunately the problem would still persist.
Here is the image to hopefully make things clearer.
So you would always need to cast outwards to find that wall, and I would suggest an above cast to find the floor to avoid already starting inside the collider.
Hmmm... I did have something in $$anonymous$$d quite like that. I will give it a try combining it with overlap shpere and see if I can get the desired results.
Your answer
Follow this Question
Related Questions
I get launched when I walk off a surface with CharacterController 0 Answers
How can I edit this script, that it will check if the character is standing on a specific layer? 0 Answers
How to get the center of a CapsuleCast or SphereCast on collision 1 Answer
RayCast ignoring mesh colliders? 2 Answers
Inconsistent results when doing line/sphere casts? 0 Answers