- Home /
 
OnTrigger causing a lag....
So i am making a game for android in which a ball will have to reach to a point to get some velocity and then to the next...for that i am using is trigger on a sphere with mesh render off...but whats happening is as soon as it touches the sphere colliders the game freezes for a sec and then every thing is smooth...and the strange part is it happens for only the first collider it comes in contact with... here's my code
function Start () {
} function Update()
{
}
function OnTriggerEnter(coll:Collider) {
var gg:MOVEMENT=GetComponent(MOVEMENT);
if(coll.gameObject.tag=="wind")
{ gg.forward=gg.forward+100;
Debug.Log("hey"); }
if(coll.gameObject.tag=="wind2") {
gg.forward+=150;
Debug.Log("hey2");
} }
and i have also used different colliders..for the sphere..
Answer by fafase · Jun 29, 2012 at 08:17 PM
There is not a lot in your script but try this way in case:
 var gg:MOVEMENT;
 function Start () {
     gg = gameObject.GetComponent(MOVEMENT);
 } 
 
 function OnTriggerEnter(coll:Collider) {
     if(coll.CompareTag("wind")){ 
         gg.forward+=100;   
         Debug.Log("hey"); }
     else if(coll.CompareTag("wind2")) {
         gg.forward+=150;
         Debug.Log("hey2");   
 } }
 
              i will but what i don't understand is why it happens only with first collider..
i will but what i don't understand is why it happens only with first collider..
Answer by MryRivera · Jun 13, 2014 at 10:42 AM
I just recently had the same problem. Spent all day trying to figure out what was causing it and I think I just found it. It might be too late for you but maybe someone else can benefit from the answer. So the cause was:
Debug.Log
I just removed it and the lag was gone.
Edit:
I also found out the same problem happens when using:
.ToString();
Your answer
 
             Follow this Question
Related Questions
How do I prevent / deal with input lag on a touch interface? 3 Answers
Android lag 1 Answer
GoogleVR vs GearVR - frame dropping 0 Answers
[SOLVED] Android Lags Then Crashes When Looking Around 0 Answers