- Home /
Performance Physics.Checkbox/CheckSphere vs Collider/Trigger
Hello, I'm currently working on collision detection. I have some NPC and I need to detect when there is a wall or an obstacle to make them stop or jump.
It's quite easy to achieve. I use a trigger that I put in front of them to collide with the wall or obstacle and activate a script.
But I could do the same by using Physics.CheckBox in the Update method to see if I collide with something. My question is what is more performant generally speaking , having a GameObject with a collider/trigger and using the OnCollider/Trigger method to call a function or using the Physics class to handle this kind of collision.
Answer by Sztormu · Oct 27, 2021 at 12:41 PM
Colliders will be generally more performant because they are designed to detect collisions every frame. I guess it's because they can precalculate values before play, cache variables and so on.
Here's a nice performance benchmark of colliders vs Physics.OverlapSphere: https://www.reddit.com/r/Unity3D/comments/eye8yk/performance_results_collider_vs_overlap_test/
Static methods from Physics may be useful and more performant for non per frame calls where the collider solution might be an overkill.
Your answer
Follow this Question
Related Questions
Horizontal gravity physics on 3d game 1 Answer
Best way to move a rigidbody 1 Answer
Unity3D: Get Velocity after collision 0 Answers
Limit & Scaling Translation Rate. 0 Answers
MAKE A LEVITATING PLATFORM REACT TO A PLAYER'S JUMP? 1 Answer