#Get Mouse Positon and make player look at it
1 messages · Page 1 of 1 (latest)
To get the mouse position it depends on which input system you're using.
By default projects in 6.3 use the new input system
in which case you can either create an input action and bind it to the mouse position, or you can directly use Vector2 mousePos = Mouse.current.position.ReadValue();
As for "converting the position to an angle" that doesn't make sense without further context. You cannot make an angle out of a single point
An angle requires three points or two vectors like AB and AC in the image above
Sorry for providing not enough context, simply want my player to look at the mouse, with ange i meant like the rotation value
to do this you first need to convert the mouse position from the input system into a world space position, because it will come in as a screen-space position
YOu can do this by getting a reference to your camera and doing Vector3 mouseWorldPos = myCamera.ScreenToWorldPoint(mouseScreenPos);
You'll probably walso want to set the z position of that world space position to be the same as your player's z position, so assuming you're using a script on the player itself you would do:
Vector3 mouseWorldPos = myCamera.ScreenToWorldPoint(mouseScreenPos);
mouseWorldPos.z = transform.position.z;```
And finally you'll want to point your player at the mouse, and to do that we don't need to worry about calculating any angles or anything
Depending on if "forward" for your sprite is right or up, you would just do:
Vector3 directionToMouse = mouseWorldPos - transform.position;
transform.right = directionToMouse;
// OR if your "forward" is "up":
transform.up = directionToMouse;```
Wow thats a lot, but thak u very much!