public IEnumerator UpdateXZ(Platform platform) { EasyTouch.SetEnabled(false); var isRotated = layer.isRotated; var rotated = isRotated ? -1 : 1; angleForXZRotation = MathAngle.To360Degree(platform.defaultAngleInLayer); angleForXZRotation = isRotated ? 360 - angleForXZRotation : angleForXZRotation; angleForXZRotation *= Mathf.Deg2Rad; var firstX = CurrentAngleX; var firstZ = CurrentAngleZ; var factorX = (float)-Math.Sin(angleForXZRotation) * rotated; var factorZ = (float)Math.Cos(angleForXZRotation) * rotated; while (true) { var speed = speedXZRotation; var angleX = speed * factorX; var angleZ = speed * factorZ; if (XZisRight(firstX, firstZ)) { SetPerfectRotation(); rotateController.ReshuffleAfterXZRotation(platform); layer.isRotated = !layer.isRotated; EasyTouch.SetEnabled(true); yield break; } layerTransform.Rotate(angleX, 0, 0, Space.Self); layerTransform.Rotate(0, 0, angleZ, Space.Self); yield return(new WaitForFixedUpdate()); } }
private void FindNearestAngleY() { var between = AngleBetweenPlatforms; var delta = deltaAngelForAlignmentY; if (between == 120) { between /= 2; } var leftOrRight = Math.Round((CurrentAngleYWithAlignment % between) / between); rightAngleY = (int)(leftOrRight + ((CurrentAngleYWithAlignment - (CurrentAngleYWithAlignment % between)) / between)) * between; rightAngleY += delta; rightAngleY = MathAngle.To360Degree(rightAngleY); }
private void SetPerfectRotation() { var x = CurrentAngleX; var z = CurrentAngleZ; var leftOrRightX = Math.Round((x % 180) / 180); var leftOrRightZ = Math.Round((z % 180) / 180); rightAngleX = (int)(leftOrRightX + ((x - (x % 180)) / 180)) * 180; rightAngleZ = (int)(leftOrRightZ + ((z - (z % 180)) / 180)) * 180; rightAngleX = MathAngle.To360Degree(rightAngleX); rightAngleZ = MathAngle.To360Degree(rightAngleZ); FindNearestAngleY(); prevY = rightAngleY; layerTransform.eulerAngles = new Vector3(rightAngleX, rightAngleY, rightAngleZ); }
public IEnumerator UpdateY() { var startPosition = Input.mousePosition; startPosition.z = 30; startPosition = camera.ScreenToWorldPoint(startPosition); var angleOfPlatform = Mathf.Atan2(startPosition.z, startPosition.x) * Mathf.Rad2Deg + CurrentAngleY; while (true) { var touchPosition = Input.mousePosition; touchPosition.z = 30; touchPosition = camera.ScreenToWorldPoint(touchPosition); var angle = Mathf.Atan2(touchPosition.z, touchPosition.x) * Mathf.Rad2Deg - angleOfPlatform; angle = MathAngle.To360Degree(angle); layerTransform.rotation = Quaternion.Euler(CurrentAngleX, -angle, CurrentAngleZ); yield return(new WaitForFixedUpdate()); } }