Yesterday I watched one lesson on development in unity3d. The lesson was about handling collisions; I didn't understand one thing about optimization. Maybe someone will open the topic in more detail.

As far as I know in unity3d, objects that have a colider and a rigidbody component are divided into 2 types: static and dynamic.

  • How to understand what type of object? And which of these types is in the cache?

  • I understand you need to try to keep as few objects as possible in the cache at the same time?

  • The questions are probably pretty simple, so I apologize, I'm completely new in this area) - Alexey Vladimirovich
  • Well, if in a simplified way [further my conjectures, as if I were realizing], the unit builds a Cartesian tree to quickly calculate collisions of “limiting boxes”, if the object does not go beyond its box (fixed or rotates), then it does not need to be rearranged in the tree and therefore everything works for approximately (log ^ 2 (N) N - the number of objects). If you need to rebuild the tree, then accordingly it is still unnecessary operations + balancing the tree + memory allocation. If the collider is of a simple form (rectangle), this is where the calculation ends, otherwise you need to do more for all suspicious objects - pavel
  • intersection of their colliders in approximately sum(i,j 1,N) A[i]*A[j] - each pair of suspicious objects for the product of the number of vertices (well, maybe a little faster). Therefore, if you "collect the puzzle," it will slow down. Optimization - a simple form, a minimum of movement (better move the camera), a minimum of "hooks" of objects. I write in the comment because not sure about the correctness. - pavel

1 answer 1

On objects that you are considering there is a component Rigidbody or Rigidbody2D if you work in 2D. They have the Is Kinematic feature, if such an object is installed, it can be controlled from the code, if it is reset, it controls the PhysX object, and you ideally apply only force and impulse to it to make it move. Gravity does not Rigidbody kinematics, and dynamic objects are subject to it if the corresponding settings are made in Rigidbody .