- Home /
Child rigidbody acting strange when moving parent.
I'm working on a space exploration game and have made the player (a rigidbody) a child of the current planet. In order to keep the level of precision high I make sure that the current planet is always at (0,0). This is the code that handles that:
public class SystemMotion : MonoBehaviour
{
public Transform system;
public Transform planet1;
public Transform sun;
public PlayerController player;
private void FixedUpdate()
{
planet1.RotateAround(sun.position, new Vector3(0, 1, 0), 10 * Time.deltaTime);
planet1.Rotate(new Vector3(0, 1, 0)*Time.deltaTime);
Recenter();
}
void Recenter()
{
system.Rotate(-player.target.rotation.eulerAngles);
system.position -= player.target.position;
}
}
And this is the result: https://imgur.com/i6kKjy8
The rigidbodies are moving on their own despite the planet staying perfectly still.
Everything works fine when the SystemMotion script is inactive.
Your answer
Follow this Question
Related Questions
" You should never have a parent and child rigidbody together " ? 2 Answers
Is it possible to prevent parent rigidbody physics from effecting children rigidbodies? 1 Answer
Make a simple tree 1 Answer
Child Gameobjects are not fixed to the parent when using physics 0 Answers
Child rigidbody clipping through walls. 2 Answers