Question by
andreyazbyn · Nov 27, 2015 at 10:24 AM ·
c#camera-movementcamera movement
Camera drag move
I made a script to move the camera using the mouse(i want whatever i point my cursor at to remain at cursor position while draging)
the script moves the camera but it's very jittery
private Vector3 start;
private Vector3 end;
void Update()
{
RaycastHit hit;
Vector3 distance;
if (Input.GetMouseButtonDown(0))
{
if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit))
{
startCameraPos = Camera.main.transform.position;
start = hit.point;
}
}
if (Input.GetMouseButton(0))
{
if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit))
{
end = hit.point;
distance = end - start;
Debug.Log(distance);
transform.position = startCameraPos + new Vector3(-(distance.x), -(distance.y));
}
}
}
Comment