Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 ahere · Jun 01, 2016 at 02:41 PM · unity 5collisiontriggerbugenter

OnTriggerEnter not working all the time.

I am developing this faller platformer where the player is to reach the bottom while picking the right platforms to land on. There are also pickups for the player on the way down. When my player lands on the the blue plartforms they are meant to change color and the pickups and meant to deactivate when the player collides with them.

This does not work all the time. Sometimes the player will collide with the plartform or pickup and nothing will happen. Could anyone help me with this.

Here is the Trigger code below.

 void OnTriggerEnter2D(Collider2D target)
     {
         if (target.tag =="Door") 
 
     {
             
             cameraScript.moveCamera = false;
             DoorUI.SetActive (true);
             
              // Door open and stop the camera.
     }
       
 
      if (target.tag == "Coins") 
        {    
 
             coinCount++;
             scoreCount += 200;
             AudioSource.PlayClipAtPoint(coinSound, target.transform.position);
             target.gameObject.SetActive (false);
             
         }
        
      if (target.tag == "Life") 
        {    
                
             lifeCount++;
             scoreCount += 300;
             AudioSource.PlayClipAtPoint(lifeSound, target.transform.position);
             target.gameObject.SetActive (false);
             
             
         }
         
     if (target.tag == "Boundary") 
         {   
             
             cameraScript.moveCamera = false;
             countPoints = false;
             
             CheckGameStatus();
 
             
             
         }
         
     if (target.tag == "Deadly") 
         {   
             
             cameraScript.moveCamera = false;
             countPoints = false;
 
             
             CheckGameStatus();
                 
         }
         
 
         
 
 
      for(int i = 0; i < listener1.Length; i++)
      {
         
         if (target.gameObject == listener1[i] )
           { 
               
             musicBoostCount++;
               Debug.Log ("IT HAPPEND");
            
             
             
          } 
 
     }   
 
 
     for(int i = 0; i < listener2.Length; i++)
      {
         
         if (target.gameObject == listener2[i])
           { 
               
             musicBoostCount++;
               Debug.Log ("IT HAPPEND2");
             
                 
          } 
 
     }
 
 
     if (target.tag == "Clouds")
       {
      
        grounded = true;
     
 
       }     
 
   }`


Here is a Link to My Dev Blog with Gifs of the game in case anyone needs more info : Link

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

Answer by Nodgez · Jun 07, 2016 at 09:25 PM

Odds are that your object is moving too fast for the trigger to be calculated, effectively being positioned over the platform one frame and below it the next. You could do 1 of 2 things

  1. Clamp the downward/y movement of the player character so it can only move so quickly

  2. Since the triggers use the physics update you could increase the frequency of the fixed timestep http://docs.unity3d.com/Manual/class-TimeManager.html

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

Answer by bleachdrinker · Jun 08, 2016 at 08:09 AM

From the gifs it looks like there is a button press or some kind of trigger that allows the player to fall quickly. Like Nodgez said the movement may be to fast to detect the collision. Another suggestion would be to use a raycast to detect the collisions. Shoot a ray out from the feet for a short distance and this will allow more than the single pixel of collision detection. Not sure if this will help or not either but there is also OnCollisionStay. OnCollisionStay should at least help with the power-ups. If You use onCollisonStay I would use it as well as CollisionEnter and have CollisionStay as a backup in case Enter doesn’t trigger. RayCast and RayCast Hit would be something to look into for the fast movement.

http://docs.unity3d.com/ScriptReference/Physics.Raycast.html

http://docs.unity3d.com/ScriptReference/RaycastHit.html

http://docs.unity3d.com/ScriptReference/MonoBehaviour.OnCollisionStay.html

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

2d game end level with trigger and colission with trigger who to make a if condition 1 Answer

How do I make animation transitions a one-way street? 1 Answer

My trigger is called twice 1 Answer

OnCollisionEnter2D not being called on entering new tile once already called. 1 Answer

jump on collision enter 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