create a gameobject in front of fpsplayer

Whenever I create the object it is never truly in front of the player but randomly off to the side. I been toying with it, but cant find the problem. I think having transfrom.position.x is wrong because it doesnt take in the consideration where the x vector (forward) is pointing. I don't know how to get the object in front of the camera....

static var canThrow : boolean = false;
var throwSound : AudioClip;
var turret : GameObject;
var wall : GameObject;

var blank : GameObject; var throwForce : float;

function Update () {

` if(Input.GetKeyDown(“y”) ){

    var place : GameObject = Instantiate(blank, transform.position, transform.rotation);

    place.transform.position.x = transform.position.x + 20.0;

    var newthing : GameObject = Instantiate(wall, place.transform.position, place.transform.rotation); (false,newthing.collider.bounds,true);




@script RequireComponent(AudioSource)

The x vector is to the right, not forward, and it's in world space. Instantiate the object using

transform.position + transform.forward * 20.0

and remove the `transform.position.x` code. Also there doesn't seem to be any point in the first Instantiated object since you just destroy it immediately anyway and it's not giving you any information you don't already have, so you can take that out.

maybe you could use a code like this (C#)

// Distance from your player    
float distance   = 4;     

// Transforms a forward position relative to your player into the world space    
Vector3 throwPos = Transform.TransformPoint( Vector3.forward * distance ); 

// Instantate the object on the position    
GameObject place = Instantiate ( blank, throwPos, Quaternion.identity );