Hi,
I got game object 1 that moves around. Game object 2 is supposed to always be 1 unit behind game object.
In a script I need to set object 2’s position 1 unit back relative to object 1’s local axis, and not world space.
One way was to parent game object 2, however this is not always an option.
I’m sure it’s really simple, but I just can’t wrap my brain around it right now. How do I do this?
Well silly me try to figure this out for 2 hours, then ask the question and 2 seconds later, BAM! You figure it out.
The answer was:
GameObject.transform.TransformDirection()
For anyone else wanting to do this
you have to set object 2’s position = object 1’s position (+/-) object 1’s position.TransformDirection(the offset you want).
Something Like:
gameObject2.transform.position = gameObject1.position + gameObject1.TransformDirection(new Vector3(0, 1, -1));
Changed gameObject [1] and [2] respectively.