• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by thereal_mpellegr · Oct 31, 2013 at 04:10 PM · physicsraycastcollidercharactercontroller

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?".

Comment
Add comment · Show 7
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Tomer-Barkan · Oct 31, 2013 at 04:20 PM 0
Share

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.

avatar image instruct9r · Oct 31, 2013 at 04:25 PM 1
Share

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?

avatar image thereal_mpellegr · Oct 31, 2013 at 04:27 PM 0
Share

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?

avatar image Owen-Reynolds · Oct 31, 2013 at 05:27 PM 0
Share

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.

avatar image thereal_mpellegr · Oct 31, 2013 at 06:02 PM 0
Share

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?

avatar image Owen-Reynolds · Oct 31, 2013 at 10:28 PM 0
Share

Sizing colliders has always been an art. Adjust the radius and height yourself. The only rule is it should "feel right" during play.

Play other 3D games; rub against bushes and walls. A good collider often skips some parts, but covers some blank space.

Raycasts are semi-advanced, so maybe save them until you have all the easy stuff down.

avatar image thereal_mpellegr · Nov 01, 2013 at 06:57 PM 0
Share

Well I guess I can do that for the character models, but I am also using a vehicle model. It seems the Character Controller does not like it when the radius is larger then the height, and the collider goes from being a capsule to a sphere. This is creating some funky properties with the vehicle, and I've needed to position the huge sphere collider fairly high in the air, just so its radius will equal the size of the vehicle. I'm guessing I should use another controller, but I don't see a Vehicle Controller..

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Make Ray hit own collider 1 Answer

Guidelines for using rigidbody, collider, CharacterControllerScript, etc? 3 Answers

BoxCollider vs. RaycastAll 1 Answer

Camera raycast and rotated collider 0 Answers

Raycasting a trigger collider? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges