• 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
1
Question by CarltonSmith · Feb 14, 2014 at 10:15 PM · collisioncharactercontroller

Character Controller wont collide (not a trigger issue)

I have a cube set up as a non trigger and a character controller but OnControllerColliderHit is not working. I can get it to display a message if i use OnTriggerEnter when the cube is set up as a trigger but then the cube wont collide with anything as its now a trigger. There is also doesnt appear to be reason why this should not work but it doesnt.

void OnColliderEnter (Collision hit) { print("hit"); }

So a recap. OnTriggerEnter works but OnColliderEnter does not, nor does OnControllerColliderHit. This happens regardless of whether i have a rigidbody on anything or not so i am definitely missing something. All the other answers on the same subject when googling "character controller not colliding" unfortunately are not what i am looking for as they still dont work.

Thanks in advance!

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by whydoidoit · Feb 15, 2014 at 07:35 AM

OnCollisionEnter (not OnColliderEnter) won't be called unless there is a rigidbody attached.

OnControllerColliderHit will only be called if you move the character controller using SimpleMove or Move, while that move is occurring.

If you need more than this then you should add a rigidbody (set to isKinematic) and use OnCollisionEnter.

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

Answer by Kavorka · Feb 14, 2014 at 10:36 PM

I see the solution. I found it here.

Comment
Add comment · Show 4 · 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 getyour411 · Feb 14, 2014 at 11:24 PM 0
Share

You posted a generic link to the $$anonymous$$onoBehaviour class which every script derives from; that's not an Answer.

avatar image Kavorka · Feb 15, 2014 at 05:34 AM 0
Share

Yes it is because it says there that it is not OnColliderEnter, it is OnCollisionEnter. Thus answering the question of what is wrong with the enclosed code.

Yes it is because it shows the page where the names of all monobehaviour callbacks are listed. If you dont know them you can not search for them. A search for OnColliderEnter is empty.

Yes it is, for more people than the poster, because this is a very useful page that many have not yet found.

Have a nice day, the downvote really made me want to help out more here.

avatar image AdamScura · Feb 15, 2014 at 07:28 AM 0
Share

@CarltonSmith, I think what @$$anonymous$$avorka was suggesting (albeit in the most lazy way possible) is that you should check the spelling on your method. Try the following code:

 void OnCollisionEnter(Collision collision) 
 {
     Debug.Log("Collision Detected");
 }

Here is a link to the documentation:

http://docs.unity3d.com/Documentation/ScriptReference/$$anonymous$$onoBehaviour.OnCollisionEnter.html

avatar image CarltonSmith · Feb 15, 2014 at 10:58 PM 0
Share

I had a strange issue with mono that was creating lots of red words where there shouldnt be red words. A reinstall of unity and this works fine. Thank you all folks. (All answers upvoted).

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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

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

Related Questions

Collision Detection in Capsule Collider 0 Answers

Mesh separating from CharacterController 0 Answers

CharacterController collision detection with pendulum like object 0 Answers

Physics AddForce reduced when 3 objects are colliding 1 Answer

OnCollisionEnter Push Object Problem 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges