Hi everybody, I'm new in Unity!
When I connect two rigidbodies together with FixedJoint, it's not solid - it behaves like a spring. (The first object is "chasing" with delay the second one)
If I change "Solver Iteration Count" parameter from default 6 to for example 90 - the connection is solid, but I've read that this can drain the performance... How I can fix that?
Thanks in advance and sorry for my english ;)
Solver iterations can reduce performance, true, but you should check your FPS to see how much effect it's actually having on performance before you decide to look for another alternative. In my experience, you have to increase your solver iterations quite a lot, and then have quite a lot of physics objects before this starts becoming an issue.
The only other alternative for improving physics accuracy (that I know of) is changing the physics time step (this is how often physics are calculated per second) but that I know for a fact has serious performance side effects (if you adjust it to be higher quality). Time step differs from solver iterations because time step means how many times per second physics is calculated, whereas solver iterations is how thoroughly and accurately each calculation is performed.
Therefore, solver iterations is indeed what you should be using.
Unfortunately, you can't "fix" any drain in performance that may be caused by increasing the solver iterations. Or in other words, you can't get more accurate calculations without paying a higher processing price. :) Now, you CAN increase solver iterations for more accurate calculations, and then enhance performance a bit by raising the physics time step, but I don't recommend this because the more you raise it, the lower your physics simulations run in frames per second. If you have a game running at 60 FPS, and physics objects simulating at 30 times per second, for instance, it looks really icky.
You can fix it very easyly and efficiently. Here is my solution.
- The object your joint is attached must be parent of the object you are trying to attach.
- On start store it’s local position.
- Every frame in Update() function reset its position to initial local position.
Don’t do it in the FixedUpdate() because object will still move in every frame. The compound objects will be diamond hard but will although break as they normaly do.
This way You can fix other joints too, but it will be not that simple.