m on a project where i have to rotate my staring to some digress and when i reach that degree it should not go beyond that but it can be rotated to other side .i have achive some portion of that but problem is when i keep on moving my hand(either left or right ) the rotation goes above or less then my condition check and not let my code to re-move.
what should i do to solve that or in simple words how can i lock the rotaion angle of my stearing to not go beond 350 and less then 208 here is my code .
if(Physics.Raycast(ray,hit))
{
euler = targetItem.transform.eulerAngles;
if((hit.transform.name=="stear") && (targetItem.transform.eulerAngles.y<350&&targetItem.transform.eulerAngles.y>208))
{
print(targetItem.transform.localEulerAngles.y);
if(Input.GetTouch(i).phase == TouchPhase.Moved )
{
targetItem.transform.Rotate(0, theTouch.deltaPosition.x *3,0,Space.World);
}
}
}
How did this pass moderation? Your explanation makes very little sense.
– mattssononi got the solution for this provided by aldonaletto // declare this variable outside any function: private var angle: Vector3 = Vector3.zero; ... if (hit.transform.name=="stear" ) { if(Input.GetTouch(i).phase == TouchPhase.Moved) { // "rotate" angle.y mathematically: angle.y += theTouch.deltaPosition.x * rotationRate; // clamp it to the desired limits: angle.y = Mathf.Clamp(angle.y, 180, 350); // update target actual rotation: targetItem.transform.eulerAngles = angle; } }
– abi-kr01Then please write it as an answer and accept it or close the question.
– mattssonon