I’m trying to add a propeller to a larger rigidbody. The propeller doesn’t need to be a rigidbody itself, but I like that I can apply torque to get it to rotate in a semi-realistic manner without having to calculate equivalent rotations myself.
Attaching the propeller with a joint isn’t satisfactory, because while I can lock the unused axes, I can’t seem to stop a little residual “spring” from jostling the propeller when I move the larger rigidbody.
So I hit on the probably-stupid idea of creating an invisible rigidbody propeller and simply mapping its rotation to a visible object without a rigidbody. So:
realPropeller.transform.rotation = fakePropeller.rigidbody.rotation;
This appears to have no effect.
What am I doing wrong? Does torque not modify the rigidbody’s rotation variable?
Also, am I being unnecessarily obtuse? Is there a simple way to eliminate the spring, or to connect two rigidbodies without a joint, or to apply a semblance of force without a rigidbody?
PS: Please forgive my ignorance!
I don’t know if I completely understood your question.
Btw, I think you can simply use a GameObject without a RigidBody to represent the propeller, and attach it as child of the GameObject with the RigidBody.
The code for parenting could be:
propellerGameObject.transform.parent = gameObjectWithRigidBody.transform;
Because the propeller hasn’t a RigidBody attached, no force acts on it.
The propeller is child of the other GameObject with a RigidBody attached which can be influenced by forces. Because the propeller is a child of it, it will inherit the parent translation and rotation (basically it follows parents movement: if parent rotates it rotates, if parent translates it translates too).
You can set child position and rotation relative to the parent coordinate system this way:
propellerGameObject.transform.localPosition = ...// position offset from parent locale coordinate system origin
propellerGameObject.transform.localRotation = ...// rotation in relation to parent coordinate system local rotation
The propeller doesn’t need to be a
rigidbody itself, but I like that I
can apply torque to get it to rotate
in a semi-realistic manner without
having to calculate equivalent
rotations myself.
If you want to apply a torque than it must be a RigidBody. If propeller doesn’t need to have a realistic physics behavior, I suggest you to avoid using a RigidBody and rotate it around the desired local axis.