- Home /
Question by
TriangleKing · Apr 30, 2013 at 02:55 AM ·
hierarchyrigid body
Following a rigid body's position in same hierarchy
Here's what I'm trying to do: I want to have a rigid body polygon (lets say it's a planet) that has forces applied with WASD/space, but I want other elements (for example, a moon at orbits the planet) to move with the planet's translation but not rotation. The moon doesn't need to be a rigid body or have any physics behavior.
Would it be possible for the planet and moon to be children of the same parent (eg a planet system object that keeps track of data relevant to both moon and planet)? I'm pretty new to Unity and don't yet have an intuition for good organization and what's possible/easy.
Comment
Best Answer
Answer by robertbu · Apr 30, 2013 at 02:32 PM
You can code one object to follow another without making them parent/child:
var goFollow : GameObject;
var offset : Vector3;
function Start() {
goFollow = GameObject.Find("Planet");
if (goFollow == null)
Debug.Log("Game object 'Planet' not found");
offset = transform.position - goFollow.transform.position;
}
function Update() {
transform.position = goFollow.transform.position + offset;
}