cool,my 100th post
ok, been working on a 3d character base game. And want to set the character look towards the mouse(like it will change its direction towards the mouse pointer).
As the character is on a floor and want to make the character look towards the mouse positions or like where ever the mouse goes. Want to set this position related to y axis on the character.
And the view from the camera is like in a perspective manner not from the top down.
As found some top down script but that didn’t worked thou lot of tweaking gone through.
You must have been asking all the right questions
Thanks for your contribution to the forum.
The Camera class has a method called ScreenToWorldPoint that reports the world-space location of a pixel onscreen. You can get the mouse’s screen position with Input.mousePosition. You will probably just need to get the world position of the mouse, and the use Quaternion.LookRotation to rotate your character to look at that point.
This is the code that was talking about, found from the community forum.
Vector3 mouseScreenPosition = new Vector3(Input.mousePosition.x, Input.mousePosition.y, Camera.main.transform.position.z);
Vector3 mouseWorldPosition = Camera.main.ScreenToWorldPoint(mouseScreenPosition);
mouseWorldPosition.y = 0;
transform.LookAt(mouseWorldPosition, rotationY,Vector3.up);
It doesn’t work since Rotation isn’t
defined