Instantiating object in the wrong place,Instantiate object at mouse point getting wrong coordinates
Hi all,
I have seen this question asked a couple of times but the answers don't seem to be working.
I 'm working on an RTS and want to place a gameobject on the mouseposition. This works, but the object is placed in the wrong location.
The picture below shows a raycast of where my mouse is. But the object (cube, bottom left of the terrain) gets instantiated nowhere near the raycast.
This is the code i'm using to get the position, what am I doing wrong?
toBuild.build(Camera.main.ScreenToWorldPoint(hit.point));
Answer by fahadbilal · Jun 21, 2020 at 12:07 PM
brother try this instead of camera.main.screentoworldpoint target = transform.GetComponent().ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, transform.position.z)); i hope you got it this is the best solution i am using in my projects