How can i make a circular move

Hi! I’m really new to scripting and i really don’t know anything.I’m trying to make the movements of the earth and the moon around the sun (figuring movements where circular) and i’m triying with transform.Translate but i don’t know how to make it move around the sun. Thanks in advance!:slight_smile:

Youll want to do something like this

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

public class RotateAround : MonoBehaviour
{

    public GameObject rotateAround;
    public int speed;
    private Vector3 axis = Vector3.up;

 
    // Update is called once per frame
    void Update()
    {    
        transform.RotateAround(rotateAround.transform.position, axis, speed * Time.deltaTime);
    }
}

Note: you can change the axis to any other vector based on which axis you want it to orbit

1 Like

What you called “rotateAround” i called “sun” but when i press play it show up a message that says the variable sun of my script has not been assigned. How do i assign the sun variable to the sun object? Probably i have like 2 IQ sorry.

A public variable will show up in the inspector on the object you place the script on. Dont rename anything in the script, rather add it as a component on the object you want to orbit the sun (aka earth) and click and drag the sun object from the hierachy into the inspector (under the RotateAround component) to the GameObject field “Rotate Around”

1 Like

Oh really thank you i think i got it <3

1 Like