Follow another GameObject as if it were a child of it

Hi,

So, this question is simple enough, but still proved to be more advanced than my math skills =(. I would like to have an object following another object as if it was its child, but without changing the parenting. So say, object A is at position X, and object B is at position Y. I dont want anything like objectA.position = objectB.position + offset… because this would not be the same as a child would be. A child object will rotate as if the parent was its pivot, and this is what I am having trouble doing.

Basically I wanted to be able to say “start following this guy” and on update or something I keep updating its position as if I had attached it as a child of the other object. I tried stuff like getting the cross from objectToFollow.forward and direction from objectToFollow towards follower… and then getting the angle and then every frame applying a rotation to the objectToFollow rotation to get where I want it to be… but as simple as this problem seem to be I cannot get my head around it, I actually don’t know how in the world Unity does it… anyone knows?

Best,
Allan

The simple way would be to have an empty child gameObject offset from objectB. You can then move objectA to the position and orientation of the empty child. objectA remains not parented.

There is probably an alternative around using the localPosition of objectB.

Thanks moonjump.

Im aware of that option, but I was looking more for a… mathematics solution. Didnt want to create more game objects… and well, Unity does the math behind the enemy lines, I just am too noob at it to figure it out.