- Home /
How do I combine Orbiting with mouse drag and with a button click?
Good day all!
I have like a model viewer setup and would like to know, how do I go about combining both mouse drag and click on a button to orbit/rotate the model?
This is what I have in my Update:
if (Input.GetMouseButton(0))
{
if(isZoomedOut)
{
x += Input.GetAxis("Mouse Y") * xSpeed * 0.02f;
x = ClampAngle(x, xMinLimit, xMaxLimit);
Quaternion rotationX = Quaternion.Euler(x, 0f, 0f);
thisObjX.localRotation = Quaternion.Slerp(thisObjX.localRotation, rotationX, dampSpeed * Time.deltaTime);
}
else
{
xZoom += Input.GetAxis("Mouse Y") * xSpeed * 0.02f;
xZoom = ClampAngle(xZoom, xMinLimit, xMaxLimit);
Quaternion rotationX = Quaternion.Euler(xZoom, 0f, 0f);
zoomObjX.localRotation = Quaternion.Slerp(zoomObjX.localRotation, rotationX, dampSpeed * Time.deltaTime);
}
}
if (Input.GetMouseButton(0))
{
if(isZoomedOut)
{
y += -Input.GetAxis("Mouse X") * ySpeed * 0.02f;
y = ClampAngle(y, yMinLimit, yMaxLimit);
Quaternion rotationY = Quaternion.Euler(0f, y, 0f);
thisObjY.localRotation = Quaternion.Slerp(thisObjY.localRotation, rotationY, dampSpeed * Time.deltaTime);
}
else
{
yZoom += -Input.GetAxis("Mouse X") * ySpeed * 0.02f;
yZoom = ClampAngle(yZoom, yMinLimit, yMaxLimit);
Quaternion rotationY = Quaternion.Euler(0f, yZoom, 0f);
zoomObjY.localRotation = Quaternion.Slerp(zoomObjY.localRotation, rotationY, dampSpeed * Time.deltaTime);
}
}
My orbit (left/right/up/down) buttons set a bool witch triggers the orbit in the Update like:
if (isOrbitUp)
{
thisObjX.localRotation = thisObjX.localRotation;
thisObjX.Rotate(Time.deltaTime * 20f, 0f, 0f, Space.World);
}
This is what my hierarchy looks like:
How do I make these 2 methods work together?
What do you mean by "mouse drag and button click"? Is it a GUI button you're clicking, or is it a key on the keyboard you're clicking?
Hello!
First of all, you need to save the rotation and the position of the mouse when you click down with your mouse.
When the mouse move, you apply the delta from the initial mouse position to the rotation!
This way the job is done!
Good luck dude!