- Home /
Question by
smirlianos · Mar 20, 2014 at 07:00 PM ·
instantiatepositionoffsetlocalrelative
GameObject's local position without parent
Hello,
This is my problem:
There is a gameObject that rotates in some game events. How can I instantiate another game object 2 units in front of it? (On the z axis)
I tried with
object1.transform.localPosition.z + 2
but it works if it has a parent only.
Any help?
Comment
Best Answer
Answer by robertbu · Mar 20, 2014 at 07:02 PM
Try this:
var pos = object1.transform.position + object1.transform.forward * 2.0;
Alternately you could convert local to global position:
var pos = object1.transform.TransformPoint(Vector3(0.0,0.0,2.0));
Your answer
Follow this Question
Related Questions
Offset Position 1 Answer
Touch position off from real position? 1 Answer
blocks being placed in an odd way 0 Answers
Instantiateon custom rotation doesn't work 2 Answers
Rigidbody move relative position ? 2 Answers