Question by
erdenutku07 · Feb 17, 2019 at 02:19 PM ·
cameracamera-movementcamera-lookcamera movement
Camera Moving Dependless On World Axis
Hi,
I'am trying to move the camera likewise the Microsoft's 3dViewer app right click. My purpose is moving the camera just on xy axis, however when I rotate the camera xy is zooming the target object, because the world's coordinate is also changing.
I guess that this is an issue about local vs world coords. However I couldn't find that how I should solve this problem.
Here is my sample code :
if (Input.GetMouseButton(1))
{
x += Input.GetAxis("Mouse X") * xSpeed * 0.02f;
y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02f;
}
x = Mathf.Clamp(x, xMinDistance, xMaxDistance);
y = Mathf.Clamp(y, yMinDistance, yMaxDistance);
vectorRightClick = new Vector3(x, y, 0);
Vector3 position = rotation * zoomDistance + target.position + vectorRightClick;
transform.position = position;
Thanks for looking.
Comment
Answer by erdenutku07 · Feb 17, 2019 at 06:35 PM
Okey, I found the answer. I should use Transform.TransformPoint method for the convert from local to world space.