Quantcast
Channel: Questions in topic: "issue"
Viewing all articles
Browse latest Browse all 827

Converting mouse position to worldpoint in 3d

$
0
0
I had this script for moving player in my 2d game: void Update () { if (Input.GetMouseButton(1)) { mousePos = Input.mousePosition; mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition); force = Vector2.ClampMagnitude(new Vector2((mousePos.x - transform.position.x), (mousePos.y - transform.position.y)), maxControlRadius); PlayerRB.velocity = force * speed; } } But now i want to upgrade to a 3d project. The problem is that i just dont know how to get the right translation from screen to world point coordinates. I have camera above the player looking down at him. But when i try to do this: Vector3 mousePos = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, Camera.main.nearClipPlane)); it always giving me coordinates (-0.1, 0.97 , 3.0). I mentioned that they are similiar to camera position (0, 10, 3). The thing is that i want to move player only in the X and Z axis. What am i doing wrong? Pleeeeease help me.

Viewing all articles
Browse latest Browse all 827

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>