Hi,
I’m using my architectural viewer with a touchscreen. (single touch, PC, coding in C#).
I’ve got few problems and I can’t find a solution.
So, my viewer has a complete GUI system, (buttons, labels, etc), and a camera which rotates aroud my object.
I had to modify my rotateCam script to make it works on the touchscreen. I use now a “Screen.width/2 - input.mousePosition.x” to define the vector of my rotation.
Here is the script:
if (Input.GetMouseButton(0))
{
xDeg = -(Screen.width / 2 - Input.mousePosition.x) * SpeedCoef * xSpeed;
yDeg = (Screen.height / 2 - Input.mousePosition.y) * SpeedCoef * ySpeed;
// Make sure that the yDeg is still in the Y limits
yDeg = ClampAngle(yDeg, yMinLimit, yMaxLimit);
//Use the AmtToRotate to rotate the camera
desiredRotation = Quaternion.Euler(yDeg, xDeg, 0);
currentRotation = transform.rotation;
//Add a damping
rotation = Quaternion.Slerp(currentRotation, desiredRotation, Time.deltaTime * RotDamp);
transform.rotation = rotation;
}
if (!Input.GetMouseButton(0))
{
currentRotation = transform.rotation;
rotation = Quaternion.Slerp(currentRotation, desiredRotation, Time.deltaTime * RotDamp);
transform.rotation = rotation;
}
First problem, when i’m clicking on the screen (or touch the touchscreen) my script take that mouse position as the new position and quickly rotates the camera. Then when I drag my mouse/finger, everything rotates as i want and if i release the mouse button or the screen it stop smoothly as I wanted too.
So, in my mind, I would like my script to use the first touch of the screen as a movement = 0 and use the dragging only to add a rotation to that start position.
Second problem, (which is related to the first I think, but there is maybe a way to solve it first as it is related to the GUIs) is that in my viewer I’ve got buttons such as home button or screenshot button which needs the cam to do not move, or take that as a rotation.
Is it possible to define different zones on the screen ? Like If mouse on the gui zone, the rotateCam script stops.
I tried the if (gui.button) → stop the rotation script then if button released → rotation script on. It doesn’t work obviously…
I really need some help, I’m stuck on that problem since a while, and I’ve got few projects wich requires the touchscreen.
Any help would be really much appreciated.
BooBi
ps sorry for the double post but I wanted to summarize my problems in one post.