- Home /
Can't raycast on Character Controller?
I have a Game Object with a Character Controller component and I am not able to collide with it using Physics.Raycast(). I am able to collide with other objects that are using box colliders, etc. I've read in other questions that Character Controller's automatically created collider doesn't allow ray casting, and that particular questioner switched components. In my case I can't do this, so what do I need to do to allow ray casting? I've tried adding another collider, but I get a message that "Replacing existing component. A Character Controller is already added, do you want to replace it with a COLLIDER_I_CHOSE?".
I have no idea why it doesn't work with the character controller's collider, but have you considered manually running the collision methods when you raycast? The Raycast will return the hit info, which includes the object, so you can try manually running the OnCollisionEnter
etc.
Do you have other colliders, attached to your character or it's children? If so the raycast might be hitting them. Use Debug.Log, to see what the hit is, when the ray shoud be hitting the character... Have you added your character to specific layer?
I noticed something interesting. The capsule collider I couldn't see from the Character Controller, but when I change the radius and height values to be those of the characters BEFORE I scaled them, then I can see the capsule surrounding the character. Is that what you are supposed to do with a Character Collider?
tr_mp (OP): Colliders try to size themselves around the object, and resize with you. But as you rescale x,y,z, the collider can get confused and be too small or large. So, YES, you are supposed to always check/adjust collider values so they look good.
Collider "auto-sizing" is merely helpful, and is in no way official or special.
I went to the mesh of my character, and looked under "Skinned $$anonymous$$esh Renderer" and found something about bounds, so I plugged the height and radius from their into the controller, but the capsule collider still isn't aligned correctly with the character. Am I supposed to just put in random values until looks about right? Or is there a way I can be more exact about this?
Answer by thereal_mpellegr · Nov 06, 2013 at 03:13 PM
I've confirmed that resizing the Character Controller component of my human entities allows a raycast to correctly collide with them. As for the vehicle, I think it just shouldn't be using a Character Controller at all because when I change the width to be large than the height, the collider turns into a sphere collider. I'm not sure what the values mean though because I'm modelling in meters and the radius and height were in the triple digits.
Your answer
Follow this Question
Related Questions
Returning list of Triangles, Vertices or Points by raycasting through a mesh (iPhone) 1 Answer
Physics.Raycast not checking layermask properly? 1 Answer
How to prevent a sphere from jumping? 0 Answers
Raycasts hit triggers disabled - force collision for specific raycast 1 Answer
How to make Ray collide with Character controller ? 1 Answer