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 MadJohny · Apr 08, 2014 at 11:36 AM · collisioncharactercontrolleroncontrollercolliderhit

OnControllerColliderHit won't trigger if not moving

Hi, I have a wall that moves and if it hits you you are supposed to die, the problem is, that is only triggered if the character controller is moving, so if you stay still, the wall goes throught you and you don't die, is there anyway way to fix this issue? By the way the wall has a rigidbody attached to it

Thanks in advance.

Edit: Adding some code by request, only the important part of it

 void OnControllerColliderHit (ControllerColliderHit hit) {
         if (hit.transform.tag == "PowerUp"){
             PowerUpScript powerUpScript = hit.transform.GetComponent<PowerUpScript>(); ......... not showing all this part since it doesn't matter
         }
         else if (hit.transform.tag == "NeonWall") {
             ApplyDamage();
         }
     }

 void ApplyDamage () {
     Destroy(gameObject);
 }

edit 2: http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.OnControllerColliderHit.html

"OnControllerColliderHit is called when the controller hits a collider while performing a Move." From my understanding, it will only be called when the character controller is moving, is that right? is there a workaroud? I really need one.

Comment
Add comment · Show 3
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 Klarax · Apr 08, 2014 at 11:39 AM 0
Share

can we see some code ?

avatar image Klarax · Apr 08, 2014 at 11:55 AM 0
Share

maybe its the physics time detection. This is set in the edit -> physics settings

avatar image MadJohny · Apr 08, 2014 at 12:25 PM 0
Share

Added the important part of the code, what is the setting I'm supposed to change inside physics settings?

2 Replies

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

Answer by Owen-Reynolds · Apr 08, 2014 at 01:38 PM

Use a standard OnCollisionEnter (I think on the wall, or on the player.)

During the physics step, then player counts as a regular stationary collider. So it can be hit by rigidbodies, and will give/get OnCollisionEnter based on their motion. As you note, OnCharConHit is only triggered when the player moves. The whole charController thing is sort of a hack:

The normal physics system moves everything together, in the "physics step", outside of all scripts. That's where it calls OnCollisionEnter/Exit. But CharControllers skip physics (to move more like a computer game player.) They move during the script. As far as the physics system is concerned, they magically teleport when it isn't looking. So they won't fire an event moving into non-rigidbodies, maybe things that are asleep... . OnCharConHit is a fix, to see all colliders, and happens during the move command (I think.)

Comment
Add comment · Show 1 · 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 MadJohny · Apr 08, 2014 at 01:46 PM 0
Share

Thanks, using OnCollisionEnter worked perfectly, but it only worked on the wall by the way

avatar image
0

Answer by Joyner · Apr 08, 2014 at 02:57 PM

yes because you are programing "OnControllerColliderHit" that means when this controller hit something not when something hit it, so, you have to use: OnCollisionEnter(GameObject c) {

   if(c.tag == "Something"){ // c have to have a rigidbody

     doSomething....

}

}

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

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

Related Questions

Character controller and colliders neither set off 'OnCollision' nor ' 'OnTrigger'; are ridigbodies mandatory? 1 Answer

How to stop CharacterController during Collider's moving? 0 Answers

How do you get an event to call when too Character Controllers hit. 1 Answer

character collider colliding with another character collider 1 Answer

OnControllerColliderHit -> GetComponent on collided object not working 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