- Home /
Rotate with two fingers
I am trying to achieve rotating an object when two fingers are rotated on the Sensel morph touchpad.
private void RotateGesture(){
if(TwoFingersDown){
if(!rotating){
startAngle = new Vector2(FingerTwoXPos,FingerTwoYPos) - new Vector2(FingerOneXPos, FingerOneYPos);
rotating = startAngle.sqrMagnitude > rotationWidth * rotationWidth;
}
else{
curAngle = new Vector2(FingerTwoXPos,FingerTwoYPos) - new Vector2(FingerOneXPos, FingerOneYPos);
var angleOffset = Vector2.Angle(startVector, currVector);
var LR = Vector3.Cross(startVector, currVector);
if (angleOffset > rotAngleMinimum) {
startAngle = curAngle;
rotating = startAngle.sqrMagnitude > rotationWidth * rotationWidth;
if (LR.z > 0) {
// Anticlockwise turn equal to angleOffset.
Debug.Log("AntiClockwise turn");
}
else if (LR.z < 0) {
// Clockwise turn equal to angleOffset.
Debug.Log("Clockwise turn");
}
}
}
else{
rotating = false;
}
}
The problem I am having is that the turn detection doesn't seem to be very accurate. Often it says anticlockwise when I am turning my fingers clockwise or vice versa. How can I fix this? I am aware the sensel morph has a lot of points and is very sensitive but I have tried adjusting the rotAngleMinimum and it doesn't seem to help. I am fine with a completely different solution to what I have here since it isn't really working anyways. I also need to be able to differentiate between a two finger rotation and a two finger horizontal swipe.
Out of curiosity, does the sensel morpth use the touch input system? You could always write a custom script that uses the touch input system if so. Since by default "right click" or $$anonymous$$ouseButton(1) is 2 touches, and the Input.Touches array contains all touch info, you could easily create a script that takes the original 2 touch position, create a originalPos for both touch points, and update the rotation based on the differences from originalPos and new pos.
The sensel morph doesn't use the touch input system. You have to use its api to get touches.
Your answer
Follow this Question
Related Questions
Make object follow my finger (Touch)? 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Touch - drag different objects 1 Answer