- Home /
Question by
saifshk17 · Jun 30, 2020 at 09:11 AM ·
mouse-drag
Change the script to also work with Mouse drag?
I have a touch script to rotate the camera around the orbit. I would like to add mouse click and drag function as well more like an || function to this script. How do I achieve it?
private float xDeg = 0.0f;
private float yDeg = 0.0f;
private float currentDistance;
private float desiredDistance;
private Quaternion currentRotation;
private Quaternion desiredRotation;
private Quaternion rotation;
private Vector3 position;
void LateUpdate()
{
if (Input.touchCount==1 && Input.GetTouch(0).phase == TouchPhase.Moved) //Add mouse function
{
Vector2 touchposition = Input.GetTouch(0).deltaPosition;
xDeg += touchposition.x * xSpeed * 0.002f;
yDeg -= touchposition.y * ySpeed * 0.002f;
yDeg = ClampAngle(yDeg, yMinLimit, yMaxLimit);
}
desiredRotation = Quaternion.Euler(yDeg, xDeg, 0);
currentRotation = transform.localRotation;
rotation = Quaternion.Lerp(currentRotation, desiredRotation, Time.deltaTime * zoomDampening);
transform.localRotation = rotation;
}
Comment
Best Answer
Answer by saifshk17 · Jun 30, 2020 at 09:41 AM
I had to add Mouse X and Mouse Y axis to the floating variable and then it works as expected. The addition in the code is given below with the else statement:
else if (Input.GetMouseButton(0)) {
xDeg += Input.GetAxis("Mouse X") * rotationSensitivity;
yDeg -= Input.GetAxis("Mouse Y") * rotationSensitivity;
}
Your answer
Follow this Question
Related Questions
Trajectory on mouse up 0 Answers
How to deal with collision by using mouse drag? 0 Answers
How to move object with mouse at same rate of mouse - 2D 1 Answer
Move Camera once Mouse Drag is complete 2 Answers