- Home /
Help spawning an object relative to the local Z axis of an object
So I want to spawn an object to the relative forward location to the spawner but I can only make it spawn relative to the global forward direction.
This is the global rotation of the object
this is the local rotation of the object and the object spawns relative to the global z axis
So the code I am using to spawn the next object is this
public GameObject thingToMake;
Vector3 poz;
void Start ()
{
poz = new Vector3(gameObject.transform.localPosition.x, gameObject.transform.localPosition.y, gameObject.transform.localPosition.z + 4f);
Instantiate(thingToMake, poz, Quaternion.Euler(0, 0, 0));
}
So I am using Local position but it will still spawn the object relative to the global z direction and not to the local z direction.
Thanks in advance for answers.
Your answer
![](https://koobas.hobune.stream/wayback/20220612082650im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Help with firing projectiles out of turret 1 Answer
Checking if object intersects? 1 Answer
GameObject position and localPosition not changing in hiearchy, only in script. 0 Answers
Why is this spawning the bullets in the center of the game world? 1 Answer
How use local position of prefab for my instantiate ? 1 Answer