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 arboshiki · Jan 14, 2013 at 12:27 PM · collisionrigidbodycollidercharactercontroller

OnCollisionEnter does not work

Hi everyone, I have not so serious problem but I tried almost everything and it does not work. I have a player, This is my player.![alt text][1], and I have a floor object, this is my floor, ![alt text][2] I have the following function in script which is attached to floor

function OnCollisionEnter(other : Collision){

Debug.Log(other.gameObject.name);
} my player walks over the floor but it does not write anything in console, I tried many things but I could not fix it, if anyone can please help me. [1]: /storage/temp/6684-player.jpg [2]: /storage/temp/6685-wooden+floor.jpg
player.jpg (88.0 kB)
wooden floor.jpg (89.5 kB)
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

4 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by dmg0600 · Sep 19, 2014 at 09:47 AM

You could turn it around and check the collision on the player. To do so add a script to the player like this:

 function OnControllerColliderHit (hit : ControllerColliderHit) {
     Debug.Log(hit.gameObject.name);
 }

Take into account that this way you will be checking if the player has had a collision with the floor instead of checking if the floor has had a collision with the player.

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
0

Answer by Lovrenc · Jan 14, 2013 at 12:36 PM

OnCollisionEnter only happens when collision happens but AND it there was no collision inprevious FixedUpdate.

If you want to check if collision is still happening use OnCollisionStay.

Other than that, you dont want to use rigidbody on gameObject that hac character controller. Chose one on another, otherwise wierd thigs are going to be happening.

Comment
Add comment · Show 5 · 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 arboshiki · Jan 14, 2013 at 02:00 PM 0
Share

I changed function OnCollisionEnter with OnCollisionStay but it acts the same as before. and I ramoved rigidbody from player too.

avatar image Lovrenc arboshiki · Jan 14, 2013 at 02:27 PM 0
Share

Use CO$$anonymous$$$$anonymous$$ENT to write comments. Do you have gravity on character controller? How are you moving?

avatar image exorakhilas arboshiki · Sep 19, 2014 at 09:13 AM 0
Share

Hi there. I am having the same problem too :/

avatar image pako · Sep 19, 2014 at 11:06 AM 0
Share

I did some tests on this, using Unity 4.5.2 and it didn't work for me either, when I used the First Person Controller from the Standard Assets for a CharacterController. When I used a Capsule GameObject with a CharacterController component on it, it worked, provided the floor had a Rigidbody on it. $$anonymous$$aybe there's a nasty bug in Unity 4.5.2. So, I'm upgrading to the latest 4.5.4 to see if this behaves properly.

avatar image dmg0600 · Sep 19, 2014 at 11:18 AM 0
Share

It has to be with the way CharacterControllers are implemented. You should control collisions from them, not from outside the CharacterController. Check my answer below.

avatar image
0

Answer by vanshika1012 · Sep 19, 2014 at 01:08 PM

Either use rigid body or use Character controller. Although you can use both at a time but they produce unexpected results.

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
0

Answer by Tropicana · Sep 19, 2014 at 02:05 PM

You need to have a collider on the player too. Check Rigidbody Compound colliders in case you work with a hierachy of objects for the player.

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.

Follow this Question

Answers Answers and Comments

13 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

Related Questions

My Character controller is being push a little bit when i'm about the get the coins. How can i possibly detect collision and destroy the coins without actually getting affected by the colliding physics? 1 Answer

Trouble with OnCollisionEnter and Exit 1 Answer

Move Player With Capsule Collider 1 Answer

How to make jump something without using a character contoller? 2 Answers

How to adjust two colliders really close to each other w/o them colliding? 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