Question by
freedevlab · Sep 01, 2016 at 04:14 PM ·
cameramouselookat
camera and pointer help (camera look at pointer using (x,y) ?)
hi i have a problem scripting the code for controlling the camera to zooom looking at the mouse pointer i have tried for 2 days but no help please help ! how to code this ?
Comment
Just to be clear: If you click the mouse you want the current position of the mouse to become the new center of the screen? And then zoom in?
Answer by doublemax · Sep 01, 2016 at 07:25 PM
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
Camera.main.transform.LookAt( Camera.main.transform.position + ray.direction);
Camera.main.fieldOfView = 30.0f;
Your camera must have the tag "MainCamera" in order to access it with "Camera.main".
Your answer
Follow this Question
Related Questions
"Lookat" only working in one case 0 Answers
Mouse Events with Render Texture 0 Answers
Rotate towards mouse pointer 1 Answer
CATCH MOUSE CLICK EVENT ON OBJECTS 0 Answers
ScreenToWorldPoint not working with cinemachine virtual camera 1 Answer