A
A
alex4answ2019-07-16 14:20:42
Unity
alex4answ, 2019-07-16 14:20:42

Why does the game freeze on OnTriggerEnter?

Good afternoon, I can not understand why the game freezes when the player has OnTriggerEnter.
Move the player at high speed:

void FixedUpdate() {
        if (currentWalk != Direction.NONE)
        {
            checkDirection(); // когда distance <0.1f условие выше не сработает, останавливаю движение
            transform.position = Vector3.MoveTowards(transform.position, nextPosition, speed * Time.fixedDeltaTime);  //speed = 25f;
        }
    }

nextPosition = Vector3(0f,0f,7f); // initially the object is at points 0,0,0, that is, we just move it by 7 units in Z
Object isKinematic - true, there is a collider, not a trigger
Object trigger - isTrigger - true, tag - finish
void OnTriggerEnter(Collider collider)
    {
        if (collider.tag == "Finish")
        {
            success.SetActive(true); //Пробовал сюда любой GameObject, передаю по ссылке в редакторе
        }
    }

It just freezes terribly on collision (only on a droid phone), why could this be?
I tried to move the object both through the Rigidbody and in Update, and make it physical (remove kinematics, etc.) in any case, the game freezes for 0.5-1 second
Please tell me how to deal with this?
In general, even if you do not setActive, but output to the logs, it still freezes.
I reduced the speed from 25 to 5 (speed), everything is fine, but this speed is mandatory, what can I do in this case?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Gaydak, 2019-07-16
@MrMureno

hangs it right now the frieze or crashes right away?
Have you tried to check/repeat in the editor by raising the speed to fantastic?
did you collect the log from the device via Logcat? did you see what was there?
We are sure that OnTriggerEnter() does not affect anything. maybe you have a code for void OnTriggerExit() and at high speed FLYS out of the trigger and some other logic is triggered.
From the described, there is nothing obvious that could break the game - no. search deeper. simplify the test case. debugging and searching. good luck))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question