• 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 POLYGAMe · Feb 15, 2014 at 04:26 AM · collisionontriggerentertriggers

Game pauses sometimes with OnTriggerEnter

I have a player cube that passes through gates. If he hits the gates, it's game over, if it passes between, score is added. The score detection area is a cube and it is a child of the gate, which in itself is a child of another world object. The score cube has a tag of "Score", the gate has a tag of "Obstacle". This al works perfectly on my Mac but when run on iPad or iPhone, sometimes when the cube passes through the gate there is an ever so slight pause... it's enough to ruin the game, as it's an extremely fast paced game. When it pauses like that, 9/10 times it screws you up for the next gate... I can't release like this and have no idea how or why this is happening...

Here's my code for the collision (in case I have done something REALLY stupid):

 function OnTriggerEnter(Other : Collider)
 {
     if (Other.gameObject.CompareTag("Score"))
     {
         main.iScore++;
     }
     
     else if (Other.gameObject.CompareTag("Obstacle"))
     {
         main.bGameIsOver = true;
 
         for (var i = 0; i < PlayerParts.length; ++i)
         {
             PlayerParts[i].rigidbody.isKinematic = false;
             PlayerParts[i].transform.parent = null;
             
             var RandomX = Random.Range(-100, 100);
             var RandomY = Random.Range(-100, 100);
             var RandomZ = Random.Range(-100, 100);
             
             var RandomRotX = Random.Range(500, 1000);
             var RandomRotY = Random.Range(500, 1000);
             var RandomRotZ = Random.Range(500, 1000);
             
             PlayerParts[i].rigidbody.AddRelativeForce(RandomX, RandomY, RandomZ);
             PlayerParts[i].rigidbody.AddRelativeTorque(RandomRotX, RandomRotY, RandomRotZ);
         }
     }
 }

I was thinking it might be that code where I make the player cube break apart, but it's pausing when it passes through the gate as well, so that code wouldn't even be accessed...

Badly need help! Thanks :)

Comment
Add comment · Show 5
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 POLYGAMe · Feb 15, 2014 at 04:37 AM 0
Share

I should add that I am moving the objects with transform.Translate... will try with AddForce but will be a mission to get the behaviour I want.

avatar image POLYGAMe · Feb 15, 2014 at 05:17 AM 0
Share

Ok, just noticed sometimes the score trigger triggers game over ins$$anonymous$$d of score! This is driving me nuts as it is working perfectly on $$anonymous$$ac!!! Could it be because the objects are children? Don't see how that would matter and they NEED to be children.

avatar image superluigi · Feb 15, 2014 at 05:29 AM 0
Share

Since your can use addforce I'm going to assume that the objects already have a rigidbody attached. Use rigidbody.velocity ins$$anonymous$$d. Translate makes colliders ignore collisions. To give you an idea if you use translate to move something down then it'll go through the floor like it's not even there, I haven't tested this but I would assume that it also ignores trigger boxes. This won't solve the pause problem but it'll help you.

avatar image POLYGAMe · Feb 15, 2014 at 05:38 AM 0
Share

I'll try using velocity. The gates don't have rigidbodies but I'll add them and see if it works. It's odd that it's working perfectly as is on $$anonymous$$ac though.

avatar image POLYGAMe · Feb 16, 2014 at 01:20 AM 0
Share

Okay, I have tried everything... I have tried using rigid bodies and setting the velocity on startup, didn't help. I removed the score triggers and implemented the ++score code by detecting positions ins$$anonymous$$d... didn't help. I even removed all collision code and it STILL pauses every now and then. I'm thinking it's an iPhone thing. It seems to stop doing it once the game has been running for a bit. I have no idea why this is happening but it really is going to kill my game and I simply can't release like this. Has anyone had any similar issues? By the way, there is no garbage collecting going on as I am recycling my obstacles. I literally only have a few game objects in the entire scene... none are being destroyed or invoked during the game, other than the initial setup of objects.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by POLYGAMe · Feb 18, 2014 at 08:01 AM

This turned out to be the dynamic fonts. Every time a new character is displayed a new texture is created and I had the font sizes reasonably high, so I'm guessing that made it even worse. In my case, when the collision was occuring, it would trigger the Game Over text, which was big and had huge dynamic fonts. By making the fonts unicode and tweaking sizes, I fixed it all.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

19 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

Related Questions

OnTriggerEnter is not working! I have tried absolutely everything I can think of. 1 Answer

OnTriggerEnter Multiple Collisions Activating. I tried many variations, Please help (Java) 3 Answers

Some1 PLEASE HELP I SPENT HOURS trying 2 fix but nothing. My trigger / animation wont play on collision 2 Answers

How do I ignore trigger objects for collision? 0 Answers

Delayed Collisions Bug (includes video demonstration) 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