How to rotate Object relative to other objects rotation around point

I don’t know how to describe this accurately, but I want to rotate an objectA relative to another objectB’s rotation around a point (the center of objectA).

I hope this video helps to understand what I’m trying to say, I want the green box to rotate itself relative to the position of the red sphere after grabbing it.

I tried the Transform.LookAt function, but the “pin” can rotate without rotating the object itself, so thats not a solution because the object rotates to the current position of the pin when grabbing the pin, but I only want to rotate the object relatively.

Hello.

OK, i see now what you pretend. Both object rotate simultaneously arround same posit right?

Then an easy solution is to have an empty GameObject (lets call in “parent”) that contains the Box and the handler.

This parent have a collider at exatc position of redsphere, then, the user rotates the entire parent ( but the user will think is movig the handler). So, as box and handler are part of same parent they will rotate simultaneously.

Is that a solution for you?

If some of the objects is not rotating from the correct pivot, make it child of another emptygameobject and change its localposition.

 >BigParent
   >CubeParent
       >Cube
   >HandlerParent
       >Handler

Good luck!

Bye! :smiley:

Rotate the Earth around the Sun.

public class RotateAround : MonoBehaviour
{
    public Transform sun;
    public Transform earth;
    public float angles=0;

    void Update()
    {
        angles++; //for orbital rotation, or just set a fixed value to get a fixed position in the orbit
        earth.position = sun.position + Quaternion.Euler(0, angles, 0) * sun.position;
    }
}

[EDIT]
If you want a custom radius around the Sun, do this:

public float radius;

void Update()
    {
        var vRadius = new Vector3(radius, 0, radius);

        angles++;
        earth.position = 
            (sun.position - vRadius) + Quaternion.Euler(0, angles, 0) * (sun.position + vRadius);

        earth.position += vRadius;
    }