Vector 3 will not work..

void Update () {
if (Input.GetKeyDown(“q”)) {
GameObject wepon = Instantiate(Gun) as GameObject;
wepon.transform.parent = player.transform;
wepon.transform.position = new Vector3(0.37F, -0.3F, 0.5F);

this kinda work, but setting the position does not! it doesn error out, instead it just spawns somewhere else…

Where does it position it? Check the values, what are they? Are they different from the ones that you specify?

My answer is awaiting moderation. Here, try this: wepon.transform.localPosition = new Vector3(0.37F, -0.3F, 0.5F); or wepon.transform.position = new Vector3(0.37F, -0.3F, 0.5F) + player.position;

ps: it's a weapon ;)

Either way keep up the excellent quality writing.

2 Answers

2

wepon.transform.position = new Vector3(0.37F, -0.3F, 0.5F) + player.position;

Try this, the position you’re setting is on the Global Coord. and it should be Local.

Oh, right!

wepon.transform.localPosition = new Vector3(0.37F, -0.3F, 0.5F);

Either should work :slight_smile:
Hope it helps!

The first one doesn't make much sense. It doesn't take scaling and rotation of the player into account. The second one is correct ;)

Thank you! Local worked

yaay to localPosition