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 Kaze_Senshi · Jan 16, 2012 at 01:58 AM · 2dcollisioncharactercontrollerlerpzoncontrollercolliderhit

Collision with 2 CharacterControllers not precise

Hello guys, I am having a problem, I have two GameObjects, one is the player, another is a dog movimented with a simple IA. Both moviments are based on the Lerpz 2d tutorial. So both have a CharacterController attached.

With the player and the ground, the collision detection is OK. Also I am using some other objects that I need to do some calculations with the normal of the collision and it is working fine too, these ones use basically box colliders. The dog also works well with the ground.

Well, the problem is, the player collides right with the dog. They never "enter" inside the other. But the function OnControllerColliderHit is rarely called. I have to "rub" the character with the dog to active the function. I put a counter just to confirm it, I can do a lot of jumps over the dog without change the counter, can someone give me a help. The code used is:

 private var platformerController : PlatformerController = null; 
 private var counterManager : CounterManager = null;                                 
 private var x : int = 0;
 private final var RECOVER_TIME : float = 1; //Time to recover after get hurt
 private var lastHitTime : float = -10;    // The last time that the player has been hurted
 private var canBeHurted = true; // If the player can be hurted
                                      
 function Start()
 {
     platformerController = gameObject.GetComponent( PlatformerController );
     if( !platformerController )
         Debug.Log( "This object doesn't have a platformerController " );
         
     // This must be loaded in other level, never in the play level
     counter = GameObject.Find( "Counter" );
     if ( counter == null )
     {
         Debug.Log( "PlayerLife can't find the Counter object ");    
     }
     
     counterManager = counter.GetComponent( CounterManager );
 }
 
 //Called when the player receives a damage
 function DidHit()
 {
     counterManager.setHealth( counterManager.getHealth() - 1 );
     lastHitTime = Time.time;
     if( counterManager.getHealth() < 1 )
     {
         Destroy( gameObject );
     }
 }
                                      
 
 function OnControllerColliderHit ( hit : ControllerColliderHit )
 {
     Debug.Log( x++ );
     
     //If the character can't be hurted, finish
     if( !canBeHurted || ( lastHitTime + RECOVER_TIME ) > Time.time )
     {
         return;
     }
     
     //Checking risks
     
     //Enemies
     var enemyLife : EnemyLife = hit.gameObject.GetComponent( EnemyLife );
     if( enemyLife ) //&& !platformerController.dash.isDashing )
     {
         SendMessage ( "DidHit", SendMessageOptions.DontRequireReceiver );
         return;
     }
     
     //Other traps
     //TODO:
 }


Thanks for the attention =)

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
1
Best Answer

Answer by Kaze_Senshi · Jan 22, 2012 at 01:28 PM

Well I solved this problem using a empty child-prefab with a trigger collider. Btw I noticied if I put two colliders in the same object intercepeting some space between the colliders, only one of these colliders will work. Is that true?

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

OnTriggerEnter detection too late 0 Answers

Character Controller problem 1 Answer

Character Controller OnControllerColliderHit never called. 0 Answers

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


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