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 /
  • Help Room /
avatar image
1
Question by metiss_ · Sep 09, 2015 at 04:16 PM · unity 5triggerunity 2dcollider2d

OnTriggerEnter2D called without collision

I am kinda new to unity so please bear with me. I am making a 2D game where the player and the enemy game object both have colliders. There are different types of enemies which generally have either box collider 2d or polygon colliders 2d. When the game starts i spawn the player and spawn obstacles every 2.5 seconds using a coroutine. To each enemy, i have a trigger collider and a script attached to check if it has collided with the player. The problem is that the OnTriggerEnter2D method is called sometimes at the very start of the game when the first enemy is spawned and the enemy has not even touched the player. Hence my player dies at the beginning of the game. This is random as in, it happens with different enemies.. and it happens once in 10 times when i play the game in editor. I am stuck on this problem for 3 days.. please help

 void OnTriggerEnter2D (Collider2D other)
 {

     if (other.gameObject.CompareTag ("Player")) {

             
         if (other.gameObject.GetComponent<PlayerController> ().isDead == false) {

             if (gameObject.CompareTag ("Destroyable") && !playerController.ispassThroughSpellCasted ()) {
                 Destroy (gameObject);
                 print ("setting player dead 3");
                 playerController.playerIsDeadOrNo (true);

             } else if (gameObject.CompareTag ("FallsToGround")) {

                 if (!playerController.ispassThroughSpellCasted ()) {
                     print ("setting player dead 2 with gameobject : " + gameObject.name);
                     playerController.isDead = true;
                 } else {

                     switch (PlayerPrefs.GetInt ("levelNo")) {
                     case 0:
                         TriggerKidLevel ();
                         break;
                     case 1:
                         TriggerNormalLevel ();
                         break;
                     case 2:
                         TriggerProLevel ();
                         break;
                     
                     }

                     playerController.isDead = false;
                 }
             } else {

                 if (!other.gameObject.GetComponent<PlayerController> ().ispassThroughSpellCasted ()) {

                     playerController.isDead = true;
                     print ("setting player dead 1 with gameobject : " + gameObject.name);

                     if (gameObject.GetComponent<Animator> () != null) {
                         gameObject.GetComponent<Animator> ().SetTrigger ("playerIsDead");
                     }
                     return;
                 } else {
                     playerController.isDead = false;
                 }
             }
         }    
     }


 }


The line "setting player dead 1 with gameobject : " is printed on logs with different enemy object names each times...

Comment
Add comment · Show 2
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 holczhauser · Nov 09, 2015 at 11:06 PM 0
Share

any solution ? I have the same issue !

avatar image ARKMs · Nov 10, 2015 at 02:23 PM 0
Share
  1. Verify that is not a enemy with tag 'Player'.

  2. Add this lines before 'playerController.isDead = true'

    Debug.Log("Hi", this); Debug.Break();

This is going to mark the enemy how is killing the player, in the hierarchy tab and pause the game and maybe you can see what is happening.

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

31 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 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

2D Collision Best Practice 0 Answers

how to load panels in a platformer game? 0 Answers

How to make fast a coroutine 1 Answer

How to stick to an object when a button is pressed Unity 2d 0 Answers

Unity 2d Collision Glitch Help 0 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