- Home /
Empty GameObjects fly away.
As the title implies, I'm having a bit of a situation. I have a character prefab with some child objects that are empty managers for more child objects.
I move my character by adding force to it.
There are issues where if my character moves (at all) it will "throw" its empty child objects all over the place (which makes it hard to use them as managers since they're now 50 miles from my character).
I'm not entirely sure why, though I'm guessing that it's because of the whole "moving by force" business, since the empty GameObject goes so much farther than the parent.
So my question is:
Is the problem of empty GameObjects flying all over the place a result of adding force to the master parent? And if it is, what should I do to stop it from happening?
I'm guessing I need to zero the forces on the GameObjects but I'm having a hard time wrapping my mind around this.
(To give you an idea, this is how my character moves)
rigidbody.velocity = transform.forward * animatedMoveSpeed;
rigidbody.AddForce(0, animatedAltitudeSpeed, 0, ForceMode.Impulse);
rigidbody.AddTorque(0, Mathf.Deg2Rad * animatedTurnSpeed, 0, ForceMode.Impulse);
SpeedClamp ();
Revision 1- The manager game objects just have a transform and a script.
Do these empty GOs contain rigidbody components? Consider making them kinetic (or just remove them) if they do.
No rigidbodies, just a transform and a script.
I tried adding a rigidbody (without colliders) just to see how it went and it behaved exactly the same as it was before, which is why I'm inclined to call it an issue of force.
Answer by carrollh · Feb 03, 2015 at 12:51 AM
It sounds like your "empty game objects" have rigidbodies. Which are colliding with your character's and being blasted all over. Try making the ones you don't want moving around kinetic (check box) or just remove them all together and use a collider for interactivity if you don't need to physically push them. Or you could add them to their own layer and add the character to another and then tell the Physics engine to ignore collisions between those specific layers. Physics.IgnoreLayerCollision
Unfortunately, they do not. They have their transform and one script (that acts as the managing script). As far as I know they're not doing any kind of colliding, since one of the managers is placed in front of the character, and after turning it goes...well, more "in front".
Well, if nothing else you could always put a script on the empties that updates their local position and rotation every update cycle. And by "updates" I mean puts it back in place with transform.position = the Vector3 position of something like an attachment point on your character.
Tried that, but nothing going, although I may have found the problem. I was assigning their localposition to be the same as the parent position (which meant they were, say, 110 units away from the parent because the parent was at 110).
Answer by Ashsaber · Feb 04, 2015 at 05:24 AM
False alarm, false alarm; I had assigned their localPosition to be the same as their parent, so as a result the little floating weapons thought they needed to be in a vastly different position from where they really were supposed to be.
All fixed now. :D