- Home /
I have a bug where addForce leaves behind some objects - any ideas?
Bug video short: https://www.youtube.com/watch?v=E9TGK_P9Jg0
How this works: I'm adding force to a child object, thrusters, and normally that won't move the parent object (the entire ship). But I added a fixed joint to the root transform, connected to the thrusters, so now it moves almost all of the ship! Except the turret part! The turret part is a child of the root transform, like the rest of the ship. So it should move too! But doesn't! I have no idea why this particular part is left behind when forces are applied. Even rotation, as clunky as it is now, shows the parenting works... for rotation only!
So far to fix I tried: disabling the only "different" script attached to the turret sub-hierarchy, for laser, since that controls it's own independent rotation... no change... And the root is a variant, that shouldn't matter though... And I've checked there's no rigidbodies set to kinematic... most the ship has no rigidbodies, just the thrusters and root right now with just default settings...
I have no idea what's up... Any ideas Unity Answers?
Answer by nastajus · Jan 02, 2020 at 07:47 PM
Ok, so I just figured it out after posting this. So I'd designed my scripts to be as minimalist as possible, where just attaching it handles everything else. And one of the things it the laser script does for convenience -- which I'd forgotten until I just tried re-attaching it and retracing it all now from scratch -- is it dynamically adds rigidbody at runtime.... and the default rigidbody settings are problematic.
So by changing the turret's default rigidbody to enable kinematic, the turret follows the ship now.
And the rigidbody gets added during Awake. So even though I disabled the script in my initial debugging attempt, Awake still executes, so the Rigidbody still gets added, unbeknownst to me.
What I don't understand is why I don't need kinematic on most-child thruster gameobjects, nor on the most-parent root object, but I do need it on the middle-of-hierarchy gameobject for the turret?...
Can someone explain that?
Edit: I recall reading somewhere that parent rigidbodies kind of ignore/absorb child rigidbodies, or something like that...
Your answer
Follow this Question
Related Questions
Access GameObjects Parents and Childs from any level of hierarchy 0 Answers
How do I move both the parent and child to a known position where I want the child to be? 1 Answer
Rigs, performace, optimize game object, expose extra transforms. Questions, questions, questions... 0 Answers