- Home /
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 :)
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.
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.
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.
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.
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.
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.
Your answer
Follow this Question
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
How do I ignore trigger objects for collision? 0 Answers
Delayed Collisions Bug (includes video demonstration) 1 Answer