Hi,
I’ve run into a nasty chain of problems involving rotations, rigidbodies and joints, and I can’t see any good way out.
I have a spaceship that is a rigidbody, in zero gravity, working fine. As child objects of that ship, I have cannons, which are made up of a body that rotates left-right, and cannon barrels that rotate up-down (children of the body). All parts of the cannons have colliders but no rigidbodies, because I want them to get hit by incoming fire, but I don’t want them to affect the movement of the ship. Body and barrel are rotated by script - at this point everything is working fine…
Initial problem: Rotation performance
… until I realize the performance of the rotations is extremely bad. Calling Rotate() on a Transform for around 10 cannons every frame drops the framerate from 60 to 20. After some research I find out that objects with colliders but no rigidbodies are not supposed to be rotated, since they’re assumed to be static by the engine. So I add a rigidbody to my cannon body, performance is fixed, but of course that opens the gate to new physics problems.
Complication #1: a rigidbody cannot be a child of a rigidbody
I try it anyway. If the cannon is kinematic, it affects the ship physics and moves it around - not good, but the cannon stays stuck to the ship properly. If the cannon is non-kinematic, and collisions with the ship are disabled, then the ship doesn’t move, but the cannon does not follow it. So I try fixed joints instead.
Complication #2: not-so-fixed joints
I had never used them before, but my understanding of fixed joints is that they should make a rigidbody stick to another with 0 tolerance - otherwise it shouldn’t be called “fixed”, right?
I moved a cannon out of the ship hierarchy, gave it a fixed joint, and set the ship as the “connected body”. That almost works, except that when the ship moves, the cannon jitters, as if the fixed joint position was updated a frame too late or something like that. My ship is moved only by AddForce(), so I know of anything in my scripts that could be causing this jitter. Physics engine bug?
I also tried setting the cannon to kinematic mode, but that seems to propagate to the connected body, and stops my ship from moving in any way.
** What is the question?**
I have several, I hope somebody can help:
- Is there any way to solve the rotation performance problem without involving rigid bodies?
- What could be causing the fixed joint jitter? If it’s a known engine problem, is there a workaround?
- If fixed joints are not the way to go, and I can’t parent a rigidbody to another, and I have to have cannons as rigidbodies because of the performance issue, is there anything else I can do besides writing my own parenting system?
Thanks for reading this far