Is it a good idea? Game Development Optimization

Viewed 37

Okay, lets say that i have 1k objects with rigidbodies and colliders. Of course my game is going to have frame drops. I thought about this: The object (a) will have a script doing this: There will be a empty object as a parent (lets say for a wall). The childs of this object will be a wall with just mesh rendered and materials and one more wall with mesh rendered, materials, rigidbody and collider. When the distance of player from the object a will be more than 100 metres, via a script i will activate the empty wall and when player distance is less than 100 i will activate the other wall. Do you believe is going to work, have anyone try this before?

ps: before anyone saying to me to try it out, I want to build a big map and because I am working I have only 1-2 hours per day to program so I am trying to save same time. Otherwise I will try it and I will writte my results. Thanks

1 Answers

Yes, It should work to disable and enable rigidbodys.

The only problem is that you want to check for the distance of 1 object is, not the whole group of rigidbodys. You would not want to store an array of all rigidbodies and disable only the ones past the specified distance. This would create a loop of 1000, which will also slow it down.

I reccomend either 1) splitting it up into batches, or 2) having one big batch.

  1. (example number: 10) batches each containing an equal anount of rigidbodys. A batch should be a parent game object with (example number) rigidbodys as children. Check the distance for one rigidbody (per batch) and if it is over the thresshold, disable the parent.
  1. Have one parent that has all rigidbodys as children. Either find distance from parent to camera, or 1 rigidbody to camera. If it is over the threshold, disable the parent. (If you detect camera to parent, even while the rigidbodies move the parent will still be in the same place, thus not disabling some when you are far away.
Related