# Rotate around with min/max Angle

Hi,

i want to rotate around the center Object, but with min/max Angles.
my script works with 360°, but i can’t limit the rotation.

Have somebody an idea? Thank you very much.

``````using UnityEngine;
using System.Collections;

public class RotateAroundScript : MonoBehaviour {

public Transform center;
public float rotationSpeed = 80.0f;
public Vector3 axis = Vector3.up;

public Transform PlayerFlip;
public float speed = 1.5f;

void Update ()
{
if (Input.GetKey (KeyCode.UpArrow) && PlayerFlip.localScale.x ==1)
{
transform.RotateAround (center.position, axis, rotationSpeed* Time.deltaTime);

}
if (Input.GetKey (KeyCode.DownArrow) && PlayerFlip.localScale.x ==1)
{
transform.RotateAround (center.position, -axis, rotationSpeed* Time.deltaTime);

}

if (Input.GetKey (KeyCode.UpArrow) && PlayerFlip.localScale.x ==-1)
{
transform.RotateAround (center.position, -axis, rotationSpeed * Time.deltaTime);

}
if (Input.GetKey (KeyCode.DownArrow) && PlayerFlip.localScale.x ==-1)
{
transform.RotateAround (center.position, axis, rotationSpeed * Time.deltaTime);

}
}
``````

I really think it would simpler to have a empty (call it spinEmpty) and either parent it to the center transform and then parent PlayerFlip to spinEmpty. Then when you want to spin it on an axis just rotate spinEmpty.

``````public float LimitSpin= 15f;

public void Spin(float amount){
float total = Mathf.Clamp( spinEmpty.transform.eulerAngles.y + amount * Time.deltaTime, -LimitSpin, LimitSpin);
spinEmpty.transform.eulerAngles = new Vector3(0f, total, 0f);
}
``````

Then call Spin() inside the Update function when ever you want it to spin.