- Home /
Delta touch trembling
hello!
Quick question guys, I use the delta mouse position (or delta touch on device) to raycast on a Plane so I can get accurate camera movement that follows the finger. this works fine, however on device there is a lot of trembling if I keep my finger quite static on screen. it seems like the accuracy is not enough with the raycast. I tried a SphereCast and a CapsuleCast with various radii but they didn't help much. it keeps trembling!
This is part of the code:
if (Input.GetMouseButtonDown(0)) {
currentTouchPos = currentTouchPos = Input.mousePosition;
getPointOnPlane (currentTouchPos, out initialTouchPos);
}
else if (Input.GetMouseButton(0)) {
previousTouchPos = currentTouchPos;
currentTouchPos = Input.mousePosition;
currentTouchDelta = findAccurateDeltaPos(currentTouchPos);
panning = true;
}
private bool getPointOnPlane (Vector3 touchPos, out Vector3 point) {
if (plane.Raycast (ray, out f)) {
point = ray.GetPoint (f);
return true;
}
return false;
}
private Vector3 findAccurateDeltaPos(Vector3 touchPos) {
Vector3 pos = Vector3.zero;
if (getPointOnPlane (touchPos, out pos)) {
Vector3 d = (initialTouchPos - pos);
return d;
}
return Vector3.zero;
}
I then simply move the camera by the "currentTouchDelta", which is the world-space delta position, calculated in the findAccurateDeltaPos method. Any ideas?
Thanks a lot
Try adding a 'dead zone.' So the camera only moves if the finger has moved x/y distance. $$anonymous$$ind of how a game controller joystick works. There is a little wiggle room to move the stick before the character actually moves.
Your answer
Follow this Question
Related Questions
IOS GUI slider 1 Answer
Dragging Camera based on Touch 0 Answers
Input.touchCount returning wrong number 0 Answers