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
3
Question by manni1238 · Jan 17, 2012 at 06:52 PM · rigidbodycharactercontrollercollision detectionmoving

Problem with CharacterController collision detection

Hi, I have a problem with the collision detection of the CharacterController component. I created a small bomb object and i want it to explode when the character touches it. The player object has a character controller object attached to it, while thethe bomb has a rigidbody and a capsule collider. As long as the bomb is moving, the method OnCollisionEnter works fine for collision detection, but as soon as it stops, I can not detect collisions anymore. I tried OnControllerColliderHit, too, but this doesn't even work for a moving bomb.

Is there a better method for the detection of collisions?

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

1 Reply

· Add your reply
  • Sort: 
avatar image
6

Answer by aldonaletto · Jan 17, 2012 at 09:45 PM

Collisions between rigidbodies and CharacterControllers are weird: OnCollision events are generated when the rigidbody hits the character, but not the other way around (except in some rare cases). These are some ways to work around this:

1- Use OnControllerColliderHit in the character script (this event isn't sent to the other object):

function OnControllerColliderHit(hit: ControllerColliderHit){
  if (hit.tag == "Bomb"){
    hit.SendMessageUpwards("Explode"); // call the function Explode in the bomb script
  }
}

2- Child a somewhat larger trigger volume to the bomb, and use OnTriggerEnter to explode it (trigger script):

function OnTriggerEnter(other: Collider){
  if (other.tag == "Player"){
    SendMessageUpwards("Explode");
  }
}

The first alternative is easier, but is tied to the player. The second solution requires you to child a trigger volume (say, a sphere with the mesh renderer disabled) to the bomb, but doesn't need any changes in the player.

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 manni1238 · Jan 18, 2012 at 04:26 PM 0
Share

Thank you, the first method works perfectly.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Character not moving on slopes 1 Answer

Stop objects from going through each other with rigidbodies 1 Answer

rotating/moving colliders with or without rigidbodies? 2 Answers

How to handle movement in a multiplayer FPS? 0 Answers

Enemy with character controller has inconsistent hit 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