Keep object straight during rotation

Hi! :slight_smile: here, there are two arm which rotate at 360°, and ther’s a ‘Carpet’ that should be straight during this rotation. how can I do for keep the carpet straight, but into the arms? Thank you:smile:

This is the problem:

This is how it should work

If can help you, the script:
```csharp
**If can help you, the script:

public class RotazionePedana : MonoBehaviour
{
public GameObject teller;
float teller_rot;
float speed = 10f;
public float maxSpeed = 10f; //modificare la velocità nell’editor non qui.
public float reverseSpeed = -10f; //modificare la velocità nell’editor non qui.
void Awake()
{
teller_rot = 0.0f;
speed = 0.0f;
}
void Update()
{
if (Input.GetKey(KeyCode.Q))
{
speed += 1;
}
if (Input.GetKey (KeyCode.E))
{
speed -= 1;
}
else if (Input.GetKey (KeyCode.W))
{
speed = speed * 0.9f; //Freni
}
if (speed > maxSpeed) speed = maxSpeed;
else if (speed < reverseSpeed) speed = reverseSpeed;
teller_rot = teller_rot + Time.deltaTime * speed;
teller.transform.localEulerAngles = new Vector3(0.0f, 0.0f,teller_rot);
}
}**
```

You haven’t explained this very well.

The question is, when the arms rotate, the carpet should be rotate, but as in the second picture that i’ve posted, instead it rotate wrong (look the firts pic). It should be rotate straight as in the second picture. Hope i’ve explained.

Unless the carpet is a child to one of the arms, or you are in fact applying rotation to the carpet, you should see no rotation.

Make sure the carpet transform is not a child of the arm. Make sure no rotation to the carpet is being applied.

You will have to use trig and reposition the carpet based on X,Y calculated from the angle…

something like this…

public float Distance = 5;
public float Angle = 0;
public float Speed = 5;


void Update()
{

  Angle += Speed * Time.deltaTime;
  if(Angle > 360)
    Angle -= 360;


 float x = Distance * Mathf.Cos(Angle);
 float y = Distance * Mathf.Sin(Angle);

 transform.position = new Vector3(x, y, 0);


}

I made so, but work very bad… but it’s possible that to solve this little problem is so complicated?

    public GameObject Arm1;
    public GameObject Arm2;
    public GameObject Carpet;
    float Arm_rot;
    float speed = 10f;
    public float maxSpeed = 10f; //modificare la velocità nell'editor non qui.
    public float reverseSpeed = -10f; //modificare la velocità nell'editor non qui.

    public float Distance = 5;
    public float Angle = 0;
    public float Speed = 5;


   
   
    void Awake()
    {
        Arm_rot = 0.0f;
        speed = 0.0f;

       
    }

    void Update()
    {
        if (Input.GetKey(KeyCode.Q))
        {
            speed += 1;

            Angle += Speed * Time.deltaTime;
            if(Angle > 360)
                Angle -= 360;
        }

        if (Input.GetKey (KeyCode.E))
        {
            speed -= 1;

            Angle -= Speed * Time.deltaTime;
            if(Angle > 360)
                Angle -= 360;
        }
       
        else if (Input.GetKey (KeyCode.W))
        {
            speed = speed * 0.9f; //Freni
        }
       
        if (speed > maxSpeed) speed = maxSpeed;
       
        else if (speed < reverseSpeed) speed = reverseSpeed;
       
        Arm_rot = Arm_rot + Time.deltaTime * speed;
        Arm1.transform.localEulerAngles = new Vector3(0.0f, 0.0f,Arm_rot);
        Arm2.transform.localEulerAngles = new Vector3(0.0f, 0.0f,Arm_rot);

        float x = Distance * Mathf.Cos(Angle);
        float y = Distance * Mathf.Sin(Angle);
       
        Carpet.transform.position = new Vector3(x, y, 0);



    }
   
   
}