- Home /
Question by
batuhancandr · May 25, 2021 at 03:38 PM ·
unityeditordeveloper
Transform.Rotate limit Help!
I am new at Unity and i want to make limit the z axis
Vector2 firstPressPos; Vector2 secondPressPos; Vector2 currentSwipe;
public Transform rightLeg;
public Transform leftLeg;
void Start()
{
}
void FixedUpdate()
{
Swipe();
}
public void Swipe()
{
/* if (Input.GetMouseButtonUp(0))
{
//save began touch 2d point
firstPressPos = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
}*/
if (Input.GetMouseButton(0))
{
secondPressPos = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
currentSwipe = new Vector2(secondPressPos.x - firstPressPos.x, secondPressPos.y - firstPressPos.y);
currentSwipe.Normalize();
if (currentSwipe.y > 0 && currentSwipe.x > -0.5f && currentSwipe.x < 0.5f)
{
Debug.Log("up swipe");
rightLeg.Rotate(new Vector3(0, 0, -80) * Time.deltaTime);
leftLeg.Rotate(new Vector3(0, 0, -80) * Time.deltaTime);
}
//swipe down
if (currentSwipe.y < 0 && currentSwipe.x > -0.5f && currentSwipe.x < 0.5f)
{
Debug.Log("down swipe");
}
//swipe left
if (currentSwipe.x < 0 && currentSwipe.y > -0.5f && currentSwipe.y < 0.5f)
{
Debug.Log("left swipe");
rightLeg.Rotate(new Vector3(0, 0, -80) * Time.deltaTime);
leftLeg.Rotate(new Vector3(0, 0, -80) * Time.deltaTime);
}
//swipe right
if (currentSwipe.x > 0 && currentSwipe.y > -0.9f && currentSwipe.y < 0.9f)
{
Debug.Log("right swipe");
rightLeg.Rotate(new Vector3(0, 0, 80)*Time.deltaTime);
leftLeg.Rotate(new Vector3(0, 0, 80) * Time.deltaTime);
}
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613034148im_/https://answers.unity.com/themes/thub/images/avi.jpg)