var adjustPosition : Vector3;
Instantiate (launcherPrefab, barrel.position+ adjustPosition, barrel.rotation);
In above script, I want Prefab instantiated slightly in front of [barrel.position].
How to?
If I set (adjustPosition)'s z value to something like 2 or 3, it represent world-coordinate, so that if character turns(barrel’s position is also turns), Instantiate position will not be match my purpose.
Try Vector3,Forward to get local z forward direction.
Try this easy setup. Place an empty game object as a child of the barrel where you want instantiation to occur. Then just use that objects transform to instantiate.
Ummm… duh… like he said. transform.forward. I prefer to use aim-and-shoot empty gameObjects objects myself and just instantiate at that position and rotation.
But…why would Vector3.Forward always be world coordinates. Makes it not very useful. Not got Unity in front of me but it seems if you use the Vector3 as a property of the object that is the local. With no object it is world.
It’s often useful to have the world axes easily available. For example, you might want to raycast straight down from an arbitrarily oriented object, or make an arbitrarily oriented object ‘jump’ by applying an impulse in the ‘up’ direction.