# GameObject to mouseposition without ray/collider

hello all , i’m trying to make a script in c# for move a GameObject to my mouse without use raycast cause i no have collider (it a spacegame ) i want to make like the move gizmo on homeworld ( in a flat plane) . i trying that but the gameobject is alway under my camera ( and move just a little bit when i move my mouse )

``````Vector3 mouse = Input.mousePosition;
mouse.z = 1.0f;
Vector3 vec = Camera.main.ScreenToWorldPoint(mouse);
transform.position = new Vector3(vec.x,0,vec.z);
``````

The mouse position (a 2D coordinate) corresponds to a ray starting at the camera position and passing through the mouse pointer in the 3D world. To convert from mouse position to 3D world, you must specify the distance from the camera in the Z coordinate passed to ScreenToWorldPoint - since you’re passing 1 in Z, that will be the distance from the camera!

You can pass a bigger distance in Z:

```Vector3 mouse = Input.mousePosition;
mouse.z = 500f; // the distance from the camera is 500
Vector3 vec = Camera.main.ScreenToWorldPoint(mouse);
transform.position = new Vector3(vec.x,0,vec.z);
```

But if this is a top-down game, you can create a logical plane perpendicular to Y and use Plane.Raycast to find the 3D point:

```void Update(){
if (Input.GetMouseButtonDown(0)){ // if click...
// create a logical plane perpendicular to Y and at Y=0:
Plane horPlane = new Plane(Vector3.up, Vector3.zero);
// get the ray from the camera...
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
float distance = 0;
// if the ray intersects the logical plane...
if (horPlane.Raycast(ray, out distance)){
transform.position = ray.GetPoint(distance); // move ship to the 3D point clicked
}
}
}
```

NOTE: This code will move the ship to which the script is attached to the point clicked; if there are other ships with this same script, all of them will get jammed at the clicked point!

hello , thanks for your answer , but i forgot to say my camera is a fully movable in all axis and rotate around a object ( like the homeworld style camera ) and i want the mouse-controllable gameobject is alway on the same y-plane (0) and in the exact position of mouse ( it for make a homeworld like move destination gizmo )

I make a little Up please , still don’t resolve my prob .

another up , please i have to make the code for the homeworld like mover destination for ship !