Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 precious-logic · Oct 07, 2013 at 01:17 PM · charactercontrollerbox collider

Collision detection between box collider and character controller

Hi

I am new on unity3d i am facing a problem on collision with my character having character contorller to an object having box collider. I have found that character controller collision can be detected using

void OnControllerColliderHit(ControllerColliderHit hit)

but this is only work and called in script which is attached with character having character collision so when i use the onControllerColliderHid it call every time which ever thing is collide with it like if my character is walking on road it called. So now what basically i want is to detect collision onCollisionEnter in the script which is attached with box having box collider and when the character collide with that box that onCollisionEnter should called but it's not calling due to character controller on my character if i add box collider on my character then it always call. However if i make the box collider istriggered then OnTriggerEnter called either character have character controller or box collider but it's not working if i just uncheck the triggered. so can any one help me in this

Comment
Add comment · Show 2
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 raimon.massanet · Oct 07, 2013 at 02:53 PM 0
Share

I think you need to rephrase your question more clearly because I have read it a couple times and I am still not sure whether I have understood what your are asking for.

From my understanding, you have it right. If you have checked the isTrigger property in the box collider, then you need to implement the OnTriggerEnter, which will be fired every time a Collider enters the trigger. What's the problem in doing that?

avatar image precious-logic · Oct 07, 2013 at 03:14 PM 0
Share

I updated it kindly check now please

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by aldonaletto · Oct 07, 2013 at 03:15 PM

Yes, OnControllerColliderHit is only sent to the CharacterController's script, and only when the character hits the collider (nothing happens when the collider hits the character). If you want to call some function in the other object's script, use SendMessage in the character script:

 void OnControllerColliderHit(ControllerColliderHit hit){
   hit.transform.SendMessage("SomeFunction", SendMessageOptions.DontRequireReceiver);
 }

This code calls the function SomeFunction in the other object's script, if it exists. In order to improve performance, it would be better to SendMessage only to the desired object - by comparing its tag, for instance:

 void OnControllerColliderHit(ControllerColliderHit hit){
   if (hit.transform.tag == "SomeTag"){
     hit.transform.SendMessage("SomeFunction", SendMessageOptions.DontRequireReceiver);
   }
 }

Comment
Add comment · Show 2 · 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
avatar image precious-logic · Oct 07, 2013 at 03:22 PM 0
Share

Is there is no other option that character controller hit detect directly on the objects which it collide onCollideEnter or any other method ?

avatar image aldonaletto · Oct 07, 2013 at 04:34 PM 0
Share

It depends on what you want to do. OnCollision events are sent to both objects, but they only occur when a rigidbody hits a collider or CharacterController, not when the CharacterController hits a rigidbody. OnTrigger events are also sent to both objects, and occur when a rigidbody or CharacterController hits the trigger, or when the trigger has its own rigidbody (usually kinematic) and is hit or hits any collider - but a trigger is "transparent": it doesn't constrain the other object's movement. OnControllerColliderHit is sent only to the character's script, and only happens when the character hits other collider. Due to the contact with the ground, this event occurs almost every physics cycle - that's why it's a good idea to filter out these collisions, leaving only the ones of interest.

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.

Follow this Question

Answers Answers and Comments

18 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 avatar image

Related Questions

Underwater fog is working but how do I prevent the world fog from turning off? 0 Answers

2D Player Gets stuck 0 Answers

I need Ready Characters. Help me !!! 1 Answer

How do i keep the box collider from rotating? 1 Answer

First Person Character Controls, How? 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