Moving Parent with child component

I want to move parent object move with child object. The problem is only child transform value is changing while moving but parent transform value remains same all the time. Any help will be appreciable.

Thank You.

If you don’t already know how, please look at this page for how to add code nicely on the forums: Using code tags properly

Then, post your relevant code for some feedback :slight_smile:

2 Likes

@methos5k is right, you need to post some sample code so that we can look at it and reply back with a possible solution.
Hope to see some sample code!

Though, in code if you make a script and apply it on the parentObject to change the transform of the current to its child, it will work. There are various ways to do this:

assuming you have a script on the parent with a public GO variable referencing the child

public GameObject child;

void Update ()
{
    transform.position = child.transform.position;
}

Cheers!

2 Likes

Thanks @iamvideep_1 … i was looking for something like you posted.

will try this

Did it get this working? :slight_smile:

@iamvideep_1 solution is problematic when we involve physics.

For example,
if we moving a child by adding velocity or AddForce at constant speed

And then if we do

transform,position = child.transform.position;

Then Child will keep accelerating out of screen.

because, transform.position will do something like this

= Child Global position + child’s local position with respect to parent = Total result.( transform.position)

There has to be better way of doing this!

2 Likes