Camera orbit not working as expected

Hi there

I’m trying to orbit an object with the camera by swiping the finger on the screen. I found the MouseOrbit script on standard assets and also the one in the wiki but it has a bug:

Too understand what i mean, get your target and turn it around to the left 140 degrees for instance. Now just ‘click’ the mouse but don’t move it. If everything is correct, no camera orbit should happen since you are not moving the mouse. You will see this is not the case, the camera will rotate to some other default position.

The problem is with the Start method that initilizae the variables:
xDeg = Vector3.Angle(Vector3.right, transform.right );
yDeg = Vector3.Angle(Vector3.up, transform.up );

Once the object is rotated, those get messed up.

Anyone was able to solve this?

The problem is most likely not to do with those lines in the Start method, since they are only called once and not in response to any user action. It is possible that the slight movement of the finger on the screen introduces a slight movement of the “mouse”. You can avoid this by ignoring any mouse movements that are less than a certain threshold value:-

if (Input.GetAxis("Mouse X") > threshold) {
  xDeg += Input.GetAxis("Mouse X") * xSpeed * 0.02f;
}

Hmm that doesn’t do the trick. Maybe I explained myself wrong since it’s very hard to explain non-visually I uploaded a video.

http://www.screencast.com/t/ODBmMWIyNDc

As you can see, I click the mouse in the center of the screen and the camera shouldn’t orbit unless I drag the mouse. It works fine at the beginning. Now, wait in the video until I take off, you’ll see I click the center and the camera orbits… I have no idea why. It seems to orbit randomly, when I continue turning it will rotate less or more.

I use the same script than on the wiki. I tried to set

xDeg = Vector3.Angle(Vector3.right, transform.right );
yDeg = Vector3.Angle(Vector3.up, transform.up );

On mouse click down, just to restart the posititioning and see if that helped, but same issue.

This is my code on LateUpdate:

[quote] if (Input.GetMouseButton(0)) { if (rotating) { xDeg -= Input.GetAxis("Mouse X") * xSpeed * 0.02f; yDeg += Input.GetAxis("Mouse Y") * ySpeed * 0.02f;

////////OrbitAngle

//Clamp the vertical axis for the orbit
yDeg = ClampAngle(yDeg, yMinLimit, yMaxLimit);
// set camera rotation

camTr.rotation = Quaternion.Lerp(camTr.rotation, Quaternion.Euler(yDeg, xDeg, 0), Time.deltaTime * zoomDampening);

// calculate position based on the new currentDistance
camTr.position= target.position - (camTr.rotation * Vector3.forward * distance);

}
}
if (!rotating Input.GetMouseButtonDown(0)) {
// only activate camera rotation if clicked in the main screen area
if (Input.mousePosition.y>CalcHeight(90) Input.mousePosition.y < CalcHeight(270) Input.mousePosition.x > CalcWidth(70)) {
rotating=true;
// restart angles, we are going to begin orbiting
xDeg = Vector3.Angle(Vector3.right, transform.right );
yDeg = Vector3.Angle(Vector3.up, transform.up );

} else if (Input.GetMouseButtonUp(0)) {
// no more orbiting
if (rotating) {
rotating=false;
}
}
[/quote]

(jezz how do I paste code in here now?)