How to make a Linear Rotation ?

I’m searching a way to make my object rotate around another one, but the movement isn’t the best to look

I’ve dropped my code and a gif of the result that I have currently

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Rotation : MonoBehaviour
{
    public GameObject[] gameNodes;
    public Transform anchorGameNode;
    public Transform anchor;
    public float rotationSpeed;
    private bool canRotate = false;

    public Quaternion RotationNode;

    private void Awake()
    {
        RotationNode = transform.rotation;
    }


    public void Update()
    {
        if (anchorGameNode != null)
        {
            foreach (GameObject gameNode in gameNodes)
            {
                if ((anchor.position.x == anchorGameNode.position.x))
                {
                    canRotate = true;
                }
                if (canRotate)
                {
                    RotateGameNodes(gameNode);
                }
            }
        }
        else
        {
            transform.rotation = RotationNode;
        }


    }

    private void RotateGameNodes(GameObject gameNode)
    {
        transform.Rotate(transform.rotation.x, transform.rotation.y, -rotationSpeed * Time.deltaTime);
        gameNode.transform.RotateAround(transform.position, -transform.position, rotationSpeed * Time.deltaTime);
        var dir = -(transform.position - gameNode.transform.position);
        var angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
        gameNode.transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);

    }
}

6619108--754024--uaT2hCxyab.gif

Why not parent one to the other? You get that automatically. It’s pretty much why we have parentable transforms in Unity.

I don’t do this cause I need them to be independants, they are just nodes, in my hope there will be more nodes of different type and abilities

Ah, but you can cheat and have a helper object parented to the node you want to rotate around, and then use the position/rotation of that helper node :slight_smile:

Could you explain a little bit more this idea ? I think this might be what want (Do you have an code example ?)

I’m sure you node has a ‘connection point’ located somewhere in its local coordinate system. That would be the point where you position the ‘helper object’ (an empty game object with only a transform). If you ‘dock’ another node, you simply use that helper object’s transform to get position and rotation. It’s the ‘manual’ way of parenting objects.

Okay I’ll try, thanks for the help