Instantiating objects at position

I’m trying to instantiate an object in front of the player. For some reason, it instantiates along the x and y values correctly, but it doesn’t take into account the player’s rotation, causing it to end up along the global z rather than the local with this:

theObject : GameObject;

function Update() {
     if (Input.GetKeyDown(KeyCode.E))
          Instantiate(theObject, Vector3(transform.position.x, transform.position.y, transform.localPosition.z + 1), transform.rotation);

localPosition is only relevant if the object is a child of another, since it’s the local position of the child compared to the parent. Use transform.forward.

Instantiate (theObject, transform.position + transform.forward * 1.0, transform.rotation);

Replace 1.0 with the desired distance.