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") ){
        audio.PlayOneShot(throwSound);

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

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

        var newthing : GameObject = Instantiate(wall, temp.transform.position, temp.transform.rotation);

            AstarPath.active.SetNodes (false,newthing.collider.bounds,true);

        Destroy(temp);
}}

I think i should use replace
temp.transform.position.x = temp.transform.position.x + 20.0;
with
temp.transform.position = temp.transform.forward *10.0;
But the doesnt work either…

i don’t quite follow your code nor even can imagine what is it for. Anyhow. if you get diferences every time it spawn it is because it is referenced to world space.

Use transform.localPosition instead.