touch camera jumping to touch position
well, this camera works perfectly in editor, even when using unity remote to test the touch inputs, but when built out and ran on emulator or downloaded from play store, the camera seems to be jumping to the touch position, ive seen two topics in which people had similar issues, but they are moving their camera in a different way then i am, how would i achieve a fix for this with my current set up (using wow camera script, modified for touch input) any help would be amazing!!!!! as ive had this issue for a year or so, with no idea how to fix it,`
checker (); if (!target) return; if(!Input.GetMouseButton(0) && moving2){ moving2 = false; }else if(Input.GetMouseButton(0) && !moving2){ if(Input.mousePosition.x > Screen.width / 2){ moving2 = true; } } Vector3 vTargetOffset;
if (target2 == null) {
if (target) {
if (Input.touchCount > 0) {
Debug.Log ("touch greater than 0 ");
foreach (Touch T in Input.touches) {
if (T.phase == TouchPhase.Began) {
Debug.Log ("began");
if (ScrollTouchID == -1) {
ScrollTouchID = T.fingerId;
ScrollTouchOrigin = T.position;
if (T.position.x > Screen.width / 2) {
moving = true;
}
}
}
if ((T.phase == TouchPhase.Ended || T.phase == TouchPhase.Canceled) && T.phase != TouchPhase.Stationary) {
Debug.Log ("ended");
if (moving) {
moving = false;
}
ScrollTouchID = -1;
}
if (T.phase == TouchPhase.Moved) {
Debug.Log ("moved");
if (T.fingerId == ScrollTouchID && moving) {
Debug.Log ("moving");
if (!spellScript.castingOpened && !spellScript.inventoryOpened) {
Debug.Log ("2");
//xDeg += T.deltaPosition.x * mouseXSpeedMod / 2;
//yDeg -= T.deltaPosition.y * mouseySpeedMod / 2;
xDeg += CnInputManager.GetAxis ("Mouse X") * mouseXSpeedMod;
yDeg -= CnInputManager.GetAxis ("Mouse Y") * mouseySpeedMod;
}
}
}
}
} else if (Input.GetAxis ("Vertical") != 0 || Input.GetAxis ("Horizontal") != 0) {
float targetRotationAngle = target.eulerAngles.y;
float currentRotationAngle = transform.eulerAngles.y;
xDeg = Mathf.LerpAngle (currentRotationAngle, targetRotationAngle, rotationDampening * Time.deltaTime);
}
if (Input.GetMouseButton (0) && !spellScript.castingOpened && !spellScript.inventoryOpened && moving2) {
xDeg += CnInputManager.GetAxis ("Mouse X") * xSpeed * 0.02f;
yDeg -= CnInputManager.GetAxis ("Mouse Y") * ySpeed * 0.02f;
} else if (Input.GetAxis ("Vertical") != 0 || Input.GetAxis ("Horizontal") != 0) {
float targetRotationAngle = target.eulerAngles.y;
float currentRotationAngle = transform.eulerAngles.y;
xDeg = Mathf.LerpAngle (currentRotationAngle, targetRotationAngle, rotationDampening * Time.deltaTime);
}
desiredDistance -= CnInputManager.GetAxis ("Mouse ScrollWheel") * Time.deltaTime * zoomRate * Mathf.Abs (desiredDistance) * speedDistance;
desiredDistance = Mathf.Clamp (desiredDistance, minDistance, maxDistance);
yDeg = ClampAngle (yDeg, yMinLimit, yMaxLimit);
Quaternion rotation = Quaternion.Euler (yDeg, xDeg, 0);
correctedDistance = desiredDistance;
vTargetOffset = new Vector3 (0, -targetHeight, 0);
Vector3 position = target.position - (rotation * Vector3.forward * desiredDistance + vTargetOffset);
RaycastHit collisionHit;
Vector3 trueTargetPosition = new Vector3 (target.position.x, target.position.y, target.position.z) - vTargetOffset;
bool isCorrected = false;
if (Physics.Linecast (trueTargetPosition, position, out collisionHit, collisionLayers.value)) {
correctedDistance = Vector3.Distance (trueTargetPosition, collisionHit.point) - offsetFromWall;
isCorrected = true;
}
currentDistance = !isCorrected || correctedDistance > currentDistance ? Mathf.Lerp (currentDistance, correctedDistance, Time.deltaTime * zoomDampening) : correctedDistance;
currentDistance = Mathf.Clamp (currentDistance, minDistance, maxDistance);
position = target.position - (rotation * Vector3.forward * currentDistance + vTargetOffset);
transform.rotation = rotation;
transform.position = position;
}
`