- Home /
How would I create a raycast that ignores Character Controller
I am currently making an foot IK system right now for my game. But despite all of my dificulties the only problem I have is that whenever I enable my character controller the collider blocks off my raycast for foot IK, so I get this floating effect. Is there any way I can make my raycast ignore my character controller. I know how to utillize layers, but the problem is that the component, character controller collider, cannot have a layer? or can it? How would I make my raycast ignore the character controller?
Answer by Cherno · Jun 06, 2015 at 11:14 AM
It's true that a component can't have a layer, only a gameObject can. However, this is irrelevant since all components on a gameObject are bound to the gameObject's layer. So just make the RayCast use a layermask that excludes the character's layer, and you should be good.
Answer by Mouton · Jun 08, 2015 at 07:27 AM
Don't set the layer to the component but to the gameobject.
GetComponent<CharacterController>().gameobject.layer = LayerMask.NameToLayer("nameOfYourGameObjectLayer")
LayerMask rayMask = 1 << LayerMask.NameToLayer("nameOfYourRayLayer");
if (Physics.Raycast(from, direction, distance, rayMask))
Debug.Log("Hit something, but not the CharacterController");
Answer by Pharaoh_ · Jun 06, 2015 at 11:57 AM
Pretty much what @Cherno said, but you can use the inbuilt "Ignore Raycast" layer on the character controller.
Thank you, for your quick replies I figured out that the problem was with the height of the character controller and that my feet were not long enough to hit the ground I will change this through some code.
Please only post answers if you have an actual solution, comments or "answers to answers" should be written as comments :) I convertd your answer to a comment.