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 · Mar 20, 2012 at 01:29 AM · 2dcollisionkinematicontriggerexitmoving platform

Adding kinematic rigidbody makes OnTriggerExit break

Hello guys, I am with a problem with collisions at high speed that are driving me crazy. One of my attempts to fix it is to add a rigidbody component to all colliders in my player object. Formerly it has two triggers in child objects and one normal capsule collider at the root object used with character controller. One trigger has a kinematic rigidbody.

I am using a parenting system of moving plataforms, the problem is when I add a kinematic rigidbody to the other two (one collider and one trigger). The OnTriggerExit does not work with one script mine, but the OnTriggerEnter always work, can some one give me a light, I have no idea why this is occuring. The code used with OnTriggerEnter and exit is below, I think that the important part of code is only the trigger parts for this issue. Thank you.

 #pragma strict 
         
                                                                                                                                                                                   
 private var movingPlataform : GameObject = null;  // The parent plataform
 private var oldPosition : Vector3;    // Last position
 private var movingDirection : Vector3;    // The direction where the plataform is moving
 private var plataformerControl : PlatformerController = null;
 
 // Player variables 
 private var playerLife : PlayerLife = null;
 private var player : GameObject = null;
 
 // The distance between the center of player and another wall to kill the player crushed
 private var crushDetectDistance : float = 1.2;
 
 // Set if this plataform can kill or not
 var canKill : boolean = false;
                                                                   
 function Awake () 
 {
     movingPlataform = gameObject.transform.parent.gameObject;
     if( !movingPlataform )
     {
         Debug.LogError( "The pushing trigger can't find its parent." );
     }
     
     //Variables to detect crush
     oldPosition = transform.position;
     movingDirection = Vector3.zero;
 }
 
 function OnTriggerEnter (other : Collider) 
 {
     var playerOb : GameObject = other.gameObject;
     var platformerController : PlatformerController = other.gameObject.GetComponent( PlatformerController );
     
     //If who collides is the player, make it a child, 
     //so the movement object and the player will share their locations
     if( playerOb.GetComponent( PlatformerController ) )
     {    
         playerOb.transform.parent = movingPlataform.transform;
         
         // Getting player life
         playerLife = other.gameObject.GetComponent( PlayerLife );
         
         // Getting player object
         player = other.gameObject;
         
         plataformerControl = platformerController;
     }
 }
 
 function OnTriggerExit (other : Collider) 
 {
     var playerOb : GameObject = other.gameObject;
     Debug.Log(  other.gameObject.name + Time.time );
     if( playerOb.GetComponent( PlatformerController ) )
     {
         plataformerControl = null;
         playerLife = null;
         playerOb.transform.parent = null;
         player = null;
     }
 }
 
 function Update () 
 {    
         if( canKill  && player != null )
         {
              var rayCastHit : RaycastHit;
              
              // Getting the moviment direction
             movingDirection = movingPlataform.transform.position - oldPosition;
             movingDirection = movingDirection.normalized;
             oldPosition = movingPlataform.transform.position;
             
             // Getting the player position
             var playerGlobalPosition = player.transform.position;
             
             Debug.DrawLine ( playerGlobalPosition , playerGlobalPosition + movingDirection*crushDetectDistance, Color.cyan );
             if( Physics.Raycast( playerGlobalPosition, movingDirection, rayCastHit, crushDetectDistance ) )
             {
                 /*if( true ||  rayCastHit.transform.gameObject.tag == "ground" )*/
             
                 // The player can`t be crushed by the moving plataform itself or by triggers
                 if( rayCastHit.transform.gameObject != movingPlataform && !rayCastHit.collider.isTrigger )
                 {
                     playerLife.killPlayer();
                     Debug.DrawLine( playerGlobalPosition, rayCastHit.point, Color.magenta, 60 );
                     Debug.Log( rayCastHit.transform.gameObject.name );
                 }
             
             }
         }
 }
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 UnseenCream · Mar 01, 2015 at 10:01 AM 0
Share

I am having the same problem with OnColliderEnter with a collider! It works if is kinematic is off, but if its on the event doesn't fire. The only thing I can think of is because it is the child of another object, although the rigidbody and collider are on it (the child object).

avatar image tanoshimi · Mar 01, 2015 at 02:18 PM 0
Share

@UnseenCream - you're describing expected behaviour. "collision events are only sent if one of the colliders also has a non-kinematic rigidbody attached." - http://docs.unity3d.com/ScriptReference/Rigidbody.OnCollisionEnter.html

avatar image meat5000 ♦ · Mar 01, 2015 at 02:21 PM 0
Share

Indeed, if you need a rigidbody to be non-kinematic but behave like a kinematic you can use its Freeze-Constraints to hold it in place, with gravity off.

0 Replies

· Add your reply
  • Sort: 

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

Collision between two kinematic rigidbody triggers 2 Answers

Collision matrix not working with kinematic rigidbodies,Kinematic rigidbodies still colliding even though disabled in matrix 1 Answer

How do I make a rigidbody2d that doesn't do anything on collision? 1 Answer

2D motion/collision: physics, or direct translation? 2 Answers

Moving a player smoothly without breaking collisions? 2 Answers


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