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
1
Question by ghaddar0292 · May 29, 2013 at 05:46 PM · collisionplayeroncontrollercolliderhitsimplemove

OnControllerColliderHit function is not called if player is not performing a move.

Hello,

In my 2D game, there is a part where boulders falls on the player and I need to detect the collisions. If my player is not performing a move the OnControllerColliderHit function is not called and I cannot detect the collisions. I have read that I can use SimpleMove(Vector3.zero); somewhere in the script (allowing gravity to be applied hence my player will be performing a move). But I am not using charactercontroller script, (required for SimpleMove). I am currently using the character motor + platforming Input controller.

What can I do to solve this issue? If I have to edit my character motor which lines should I look at?

Any help is appreciated. Thank you very much.

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
3

Answer by Owen-Reynolds · May 30, 2013 at 04:28 AM

If you read the docs, that's how it should work: "OnControllerColliderHit is called when the controller hits a collider while performing a Move." (emphasis is mine.) If means it only checks during CC.Move or CC.simpleMove.

To check for other stuff hitting you when it moves, just use a regular OnCollisionEnter.

It's a weird beast since charControllers are weird. They sort of move using "physics," but not really, since you don't want players to slide, shove or get shoved in the same way blocks would be.

Comment
Add comment · Show 7 · 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 ghaddar0292 · May 30, 2013 at 06:26 AM 0
Share

I have read the docs, and I want to force my player to make a move which is not visible to the eye in order to force the OnControllerColliderHit to be called. OnCollisionEnter does not work with character controllers. What I want to do is something like this. He used simple$$anonymous$$ove to force his character to move, but he is using the charactercontroller script. I am using the character motor script. What adjustments do I need to make in order to get the results I want. When can I know in the character motor script that the character is not moving so I can edit it and perform my move. Hope I am more clear now.

Thank you for your reply.

avatar image Owen-Reynolds · May 30, 2013 at 10:27 PM 0
Share

OnCollisionEnter really will fire when a rigidbody hits you (tested, just now.) You can put it right on the script with the CC, next to your OnConCollideHit.

The Simple$$anonymous$$ove trick isn't what it looks like. You moving Zero doesn't seem to trigger OnContCollider. Simple$$anonymous$$ove also moves you down, so will trigger if you land on something. But that's the same as using $$anonymous$$ove with -Y. Either way, you have to be pushing into the collider to count as a ControllerHit.

The exact script doesn't matter than much. If you have a CharCont component on you, and do charCont.$$anonymous$$ove then OnContColliderHit follows the same "did I ram it" rules to fire.

avatar image ghaddar0292 · May 31, 2013 at 12:46 AM 0
Share

Thanks for the reply. I must be missing something because it is not working for me. In the docs it says in the description for OnCollisionEnter "OnCollisionEnter is called when this collider/rigidbody has begun touching another rigidbody/collider." Anyways you tested it and it worked so here is my script if you can figure out what is wrong.

 function OnControllerColliderHit (hit : ControllerColliderHit)
 {
 if (hit.gameObject.tag == "Boulder")
 {
 var velocity = hit.rigidbody.velocity.magnitude;
 if(velocity > 0.1) // Crushed By Boulder
 {
 dead = true;
 }
 }
 }
 
 function OnCollisionEnter(collision : Collision) 
 {
     if (collision.gameObject.tag == "Boulder")
 {
 print("worked");
 var velocity = collision.rigidbody.velocity.magnitude;
 if(velocity > 0.1) // Crushed By Boulder
 {
 dead = true;
 }
 }
 }

$$anonymous$$y OnControllerColliderHit is being called only when the character is perfor$$anonymous$$g a move as you stated in your comment, while OnCollisionEnter is not being called at all since my message is not appearing in the console. This script is attached to the character and has a character controller attached to it. It would be ideal if OnCollisionEnter function works. Thanks again.

avatar image Owen-Reynolds · May 31, 2013 at 03:24 AM 0
Share

$$anonymous$$ove the print statement to outside the if (maybe the collision happens and the tag is messed up.) Test by putting the script (theh OnCollision part) on just a fresh, non-moving cube and drop something on it (you know it should work there.)

avatar image ghaddar0292 · May 31, 2013 at 03:40 AM 0
Share

I tried that still nothing. And the tag is working for OnControllerColliderHit so it should work for OnCollissionEnter. I know that the function will work if I drop something other than a character controller on a cube. I want to get a message when something hits the character when not making a move!

Show more comments
avatar image
0

Answer by darthbator · May 29, 2013 at 06:30 PM

Do you happen to add or activate something like a rigidbody when you do "a move" character controllers don't seem to report collisions unless they have a rigidbody attached.

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 ghaddar0292 · May 29, 2013 at 06:59 PM 0
Share

No I do not. I am using OnControllerColliderHit function which is used for detecting collisions of character controllers.

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

16 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

Related Questions

Object passes through some walls? 1 Answer

Player object falling through game environment, collision not detected with ground 0 Answers

Moving a Simple Ball [Main Player!] inside a tunnel without gravity! 1 Answer

collision wont work 1 Answer

Best practice for OnTriggerEnter detection 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